/** Utilities. * * @author Daniel Krebs * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC * @license GNU General Public License (version 3) * * VILLASfpga * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . *********************************************************************************/ #include #include #include namespace villas { namespace utils { std::vector tokenize(std::string s, std::string delimiter) { std::vector tokens; size_t lastPos = 0; size_t curentPos; while((curentPos = s.find(delimiter, lastPos)) != std::string::npos) { const size_t tokenLength = curentPos - lastPos; tokens.push_back(s.substr(lastPos, tokenLength)); // advance in string lastPos = curentPos + delimiter.length(); } // check if there's a last token behind the last delimiter if(lastPos != s.length()) { const size_t lastTokenLength = s.length() - lastPos; tokens.push_back(s.substr(lastPos, lastTokenLength)); } return tokens; } } // namespace utils } // namespace villas