Tokenize.cpp

00001 
00002 #include "Tokenize.h"
00003 
00004 
00005 using std::string;
00006 
00007 namespace Sct {
00008 
00009   Tokenize::Tokenize(const string& str,
00010              const string& delimiters) {
00011 
00012     Tokens & tokens = m_tokens;
00013     string::size_type lastPos = 0;  // where the "interesting" strings start
00014     // Find first "non-delimiter".
00015     string::size_type pos;
00016     
00017     while (true/*string::npos != pos || string::npos != lastPos*/) {
00018       pos = str.find_first_of(delimiters, lastPos); // pos of next delimiter
00019       tokens.push_back(str.substr(lastPos, pos - lastPos));
00020       if (pos==str.npos) {
00021     return;
00022       };
00023       lastPos = pos+1;
00024       if (lastPos==str.npos) {
00025     tokens.push_back("");
00026     return;
00027       };
00028       // Find next "non-delimiter"
00029     }
00030     
00031   }
00032 
00033   Tokenize::TokenVec Tokenize::tokenVec() const {
00034     TokenVec v(size());
00035     Tokens::const_iterator it=  begin();
00036     TokenVec::iterator     jt=v.begin();
00037     while (it!=end()) {
00038       *(jt++) = *(it++);
00039     };
00040     return v;
00041   }
00042 
00043 };

Generated on Mon Feb 6 14:01:36 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6