CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Utilities/General/src/Tokenizer.cc

Go to the documentation of this file.
00001 #include "Utilities/General/interface/Tokenizer.h"
00002 
00003 Tokenizer::Tokenizer(const std::string & sep, const std::string & input, bool alsoempty) {
00004   size_type i=0, j=0;
00005   while( (j=input.find(sep,i))!=std::string::npos) {
00006     if (alsoempty || (j>i) ) push_back(input.substr(i,j-i));
00007     i = j+sep.size();
00008   }
00009   if (alsoempty || (i<input.size()) ) push_back(input.substr(i));
00010 }
00011 
00012 void Tokenizer::join(std::string & out, const std::string & sep, bool alsoempty) const {
00013     for (super::const_iterator p=begin(); p!=end(); p++)
00014       if (alsoempty || (!(*p).empty()) ) { out+=*p; out+=sep;}
00015 }