CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Utilities/General/src/stringTools.cc

Go to the documentation of this file.
00001 #include "Utilities/General/interface/stringTools.h"
00002 
00003 using std::string;
00004 
00005 int replace(string & input, const string&gone, const string& it, bool multiple) {
00006   int n=0;
00007   size_t i = input.find(gone,0);
00008   while(i!=string::npos) {
00009       n++;
00010       input.replace(i,gone.size(),it);
00011       i = input.find(gone,i+(multiple ? 0 : it.size()));
00012   }
00013   return n;
00014 }
00015 
00016 void strip(std::string & input, const std::string& blanks) {
00017   size_t b = input.find_first_not_of(blanks);
00018   if (b==std::string::npos) { input.clear(); return;}
00019   size_t e = input.find_last_not_of(blanks);
00020   input = input.substr(b,e-b+1);
00021 }
00022 
00023 int replaceRange(string & input, const string&first, const string& last, const string& it, bool multiple) {
00024   int n=0;
00025   size_t i = input.find(first,0);
00026   while(i!=string::npos) {
00027     size_t e = input.find(last,i);
00028     if (e!=string::npos) {
00029       n++;
00030       input.replace(i,e+last.size()-i,it);
00031       i = input.find(first,i+(multiple ? 0 : it.size()));
00032     } else break;
00033   }
00034   return n;
00035 }