StringFunctions.cpp
Go to the documentation of this file.
00001 /*
00002  * File: String.cpp
00003  * Author: Dorian Galvez-Lopez
00004  * Date: December 2010
00005  * Description: string functions
00006  *
00007  * 
00008  * This program is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  *
00021  */
00022 
00023 #include <string>
00024 #include <vector>
00025 #include "StringFunctions.h"
00026 
00027 using namespace std;
00028 using namespace DUtils;
00029 
00030 // ---------------------------------------------------------------------------
00031 
00032 void StringFunctions::split(const std::string &s, 
00033   std::vector<std::string> &tokens, const std::string &delims)
00034 {
00035   tokens.resize(0);
00036   
00037   string::size_type first, last;
00038   first = 0;
00039   
00040   bool goon = true;
00041   while(goon)
00042   {
00043     last = s.find_first_of(delims, first);
00044     if(last == string::npos)
00045     {
00046       goon = false;
00047       last = s.length();
00048     }
00049     
00050     if(last > first)
00051     {    
00052       // add from [first-last)
00053       tokens.push_back( s.substr(first, last-first) );
00054     }
00055     
00056     first = last + 1;
00057   }
00058   
00059 }
00060 
00061 // ---------------------------------------------------------------------------
00062 
00063 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:33:00