CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
stringTools.cc
Go to the documentation of this file.
2 
3 using std::string;
4 
5 int replace(string & input, const string&gone, const string& it, bool multiple) {
6  int n=0;
7  size_t i = input.find(gone,0);
8  while(i!=string::npos) {
9  n++;
10  input.replace(i,gone.size(),it);
11  i = input.find(gone,i+(multiple ? 0 : it.size()));
12  }
13  return n;
14 }
15 
16 void strip(std::string & input, const std::string& blanks) {
17  size_t b = input.find_first_not_of(blanks);
18  if (b==std::string::npos) { input.clear(); return;}
19  size_t e = input.find_last_not_of(blanks);
20  input = input.substr(b,e-b+1);
21 }
22 
23 int replaceRange(string & input, const string&first, const string& last, const string& it, bool multiple) {
24  int n=0;
25  size_t i = input.find(first,0);
26  while(i!=string::npos) {
27  size_t e = input.find(last,i);
28  if (e!=string::npos) {
29  n++;
30  input.replace(i,e+last.size()-i,it);
31  i = input.find(first,i+(multiple ? 0 : it.size()));
32  } else break;
33  }
34  return n;
35 }
int i
Definition: DBlmapReader.cc:9
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
bool first
Definition: L1TdeRCT.cc:94
double b
Definition: hdecay.h:120
int replaceRange(std::string &input, const std::string &first, const std::string &last, const std::string &it, bool multiple=false)