StringUtil Namespace Reference

Functions

std::string trim (const std::string &s)
static int SplitString (const std::string &input, const std::string &delimiter, vector< std::string > &results)

Function Documentation

static int StringUtil::SplitString ( const std::string &  input,
const std::string &  delimiter,
vector< std::string > &  results 
) [inline, static]

Definition at line 39 of file StringUtil.h.

Referenced by MdaDiscrimAna::FillCalibArrays().

00042 {
00043   int iPos = 0;
00044   int newPos = -1;
00045   int sizeS2 = delimiter.size();
00046   int isize = input.size();
00047 
00048   vector<Int_t> positions;
00049 
00050   newPos = input.find (delimiter, 0);
00051 
00052   if( newPos < 0 ) { return 0; }
00053 
00054   int numFound = 0;
00055 
00056   while( newPos > iPos )
00057   {
00058     numFound++;
00059     positions.push_back(newPos);
00060     iPos = newPos;
00061     newPos = input.find (delimiter, iPos+sizeS2+1);
00062   }
00063 
00064   for( int i=0; i <= (int) positions.size(); i++ )
00065   {
00066     string s;
00067     if( i == 0 ) { s = input.substr( i, positions[i] ); }
00068     int offset = positions[i-1] + sizeS2;
00069     if( offset < isize )
00070     {
00071       if( i == (int) positions.size() )
00072       {
00073         s = input.substr(offset);
00074       }
00075       else if( i > 0 )
00076       {
00077         s = input.substr( positions[i-1] + sizeS2,
00078           positions[i] - positions[i-1] - sizeS2 );
00079       }
00080     }
00081     if( s.size() > 0 )
00082     {
00083       results.push_back(s);
00084     }
00085   }
00086   return numFound;
00087 }

std::string StringUtil::trim ( const std::string &  s  )  [inline]

Definition at line 29 of file StringUtil.h.

00029                                          {
00030   if(s.length() == 0)
00031     return s;
00032   std::size_t beg = s.find_first_not_of(" \a\b\f\n\r\t\v");
00033   std::size_t end = s.find_last_not_of(" \a\b\f\n\r\t\v");
00034   if(beg == std::string::npos)
00035     return "";
00036   return std::string(s, beg, end - beg + 1);
00037 }


Generated on 18 Oct 2018 for loon by  doxygen 1.6.1