Functions
genie::utils::str Namespace Reference

Utilities for string manipulation. More...

Functions

string TrimSpaces (string input)
 
string IntAsString (int i)
 
vector< stringSplit (string input, string delim)
 
string RemoveSuccessiveSpaces (string input)
 
void ReplaceStringInPlace (string &subject, const string &search, const string &replace)
 
string FilterString (string filt, string input)
 
string ToUpper (string input)
 
string ToLower (string input)
 
template<class T >
bool Convert (const vector< std::string > &input, std::vector< T > &v)
 

Detailed Description

Utilities for string manipulation.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

January 12, 2004

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Function Documentation

template<class T >
bool genie::utils::str::Convert ( const vector< std::string > &  input,
std::vector< T > &  v 
)
string genie::utils::str::FilterString ( string  filt,
string  input 
)

Definition at line 79 of file StringUtils.cxx.

80 {
81 // filter out from 'input' all characters that can be found in 'filt_elements'
82 
83  string filtered_string = input;
84  string::size_type pos = 0;
85 
86  while( (pos = filtered_string.find_first_of(
87  filt_elements, pos)) != string::npos )
88  filtered_string.erase(pos,1);
89  return filtered_string;
90 }
static int input(void)
Definition: code.cpp:15695
string genie::utils::str::IntAsString ( int  i)

Definition at line 29 of file StringUtils.cxx.

30 {
31  ostringstream os;
32  os << i;
33  return os.str();
34 }
string genie::utils::str::RemoveSuccessiveSpaces ( string  input)

Definition at line 52 of file StringUtils.cxx.

53 {
54 // this method trims white space that may be found within an expression...
55 // eg. "stop pressing the spacebar" -> "stop pressing the spacebar"
56 
57  string trimmed = input;
58 
59  string::size_type pos = 0;
60 
61  while( (pos = trimmed.find_first_of(" ", pos)) != string::npos ) {
62  if( trimmed[++pos] == ' ' ) trimmed.erase(pos--,1);
63  }
64  return FilterString("\n",trimmed);
65 }
static int input(void)
Definition: code.cpp:15695
string FilterString(string filt, string input)
Definition: StringUtils.cxx:79
void genie::utils::str::ReplaceStringInPlace ( string subject,
const string search,
const string replace 
)

Definition at line 67 of file StringUtils.cxx.

69 {
70 // Searches the string "input" for "search" and replaces this with "replace"
71  size_t pos = 0;
72  while ((pos = subject.find(search, pos)) != std::string::npos) {
73  subject.replace(pos, search.length(), replace);
74  // move to end of replaced string
75  pos += replace.length();
76  }
77 }
Definition: search.py:1
vector< string > genie::utils::str::Split ( string  input,
string  delim 
)

Definition at line 36 of file StringUtils.cxx.

37 {
38 // split a string of 'delimiter' separated values and return each string
39 // part as a vector<string> element.
40 
41  vector<string> string_parts;
42 
43  while(input.find_first_of(delimiter) < input.length()) {
44 
45  string_parts.push_back( input.substr(0, input.find_first_of(delimiter)) );
46  input = input.substr(input.find_first_of(delimiter)+1, input.length());
47  }
48  string_parts.push_back(input);
49  return string_parts;
50 }
static int input(void)
Definition: code.cpp:15695
string genie::utils::str::ToLower ( string  input)

Definition at line 98 of file StringUtils.cxx.

99 {
100  for(unsigned int i=0; i<input.size(); i++) input[i] = tolower(input[i]);
101  return input;
102 }
static int input(void)
Definition: code.cpp:15695
string genie::utils::str::ToUpper ( string  input)

Definition at line 92 of file StringUtils.cxx.

93 {
94  for(unsigned int i=0; i<input.size(); i++) input[i] = toupper(input[i]);
95  return input;
96 }
static int input(void)
Definition: code.cpp:15695
string genie::utils::str::TrimSpaces ( string  input)

Definition at line 18 of file StringUtils.cxx.

19 {
20  if( input.find_first_not_of(" \n") != 0)
21  input.erase( 0, input.find_first_not_of(" \n") );
22 
23  if( input.find_last_not_of(" \n") != input.length() )
24  input.erase( input.find_last_not_of(" \n")+1, input.length() );
25 
27 }
static int input(void)
Definition: code.cpp:15695
string RemoveSuccessiveSpaces(string input)
Definition: StringUtils.cxx:52