GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
genie::utils::str Namespace Reference

Utilities for string manipulation. More...

Functions

string TrimSpaces (string input)
 
string IntAsString (int i)
 
vector< string > Split (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 <c.andreopoulos cern.ch> University of Liverpool
Created:
January 12, 2004
License:
Copyright (c) 2003-2024, 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.

Referenced by CalcTotalXSec(), Configure(), genie::BaryonResList::DecodeFromNameList(), GenerateEvent(), genie::Decayer::LoadConfig(), RemoveSuccessiveSpaces(), and SaveGraphsToRootFile().

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 }
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.

References FilterString().

Referenced by TrimSpaces().

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 }
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 }
vector< string > genie::utils::str::Split ( string  input,
string  delim 
)

Definition at line 36 of file StringUtils.cxx.

Referenced by genie::AlgConfigPool::AddBasicParameter(), genie::AlgConfigPool::AddParameterMatrix(), genie::AlgConfigPool::AddParameterVector(), genie::AlgConfigPool::AddRootObjParameter(), genie::CmdLnArgParser::ArgAsStringTokens(), CalcTotalXSec(), genie::TuneId::CheckDirectory(), Configure(), CreateFidSelection(), CreateRockBoxSelection(), genie::GVldContext::Decode(), genie::GVldContext::DecodeENERGY(), genie::BaryonResList::DecodeFromNameList(), genie::Algorithm::FindConfig(), genie::utils::xml::FindNode(), GenerateEvent(), genie::utils::system::GenieMajorVrsNum(), genie::utils::system::GenieMinorVrsNum(), genie::utils::system::GenieRevisVrsNum(), GetAlgorithms(), genie::utils::system::GetAllFilesInPath(), GetCommandLineArgs(), genie::utils::xml::GetDoubleArray(), genie::flux::GNuMIFluxXMLHelper::GetDoubleVector(), genie::utils::xml::GetIntArray(), genie::flux::GNuMIFluxXMLHelper::GetIntVector(), GetNeutrinoCodes(), GetPDGCodeListFromString(), GetTargetCodes(), genie::utils::xml::GetXMLFilePath(), genie::NtpMCJobConfig::Load(), genie::flux::GJPARCNuFlux::LoadBeamSimData(), genie::XSecScaleMap::LoadConfig(), genie::CascadeReweight::LoadConfig(), genie::QvalueShifter::LoadConfig(), genie::Decayer::LoadConfig(), main(), genie::utils::app_init::MesgThresholds(), genie::flux::GFlavorMap::ParseFixedfracString(), ParseFluxFileConfig(), ParseFluxHst(), genie::flux::GFlavorMap::ParseMapString(), genie::geometry::GeomVolSelectorBasic::ParseSelection(), and genie::Messenger::SetPrioritiesFromXmlFile().

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 }
string genie::utils::str::ToLower ( string  input)

Definition at line 98 of file StringUtils.cxx.

Referenced by genie::utils::gsl::Integration1DimTypeFromString(), and genie::utils::gsl::IntegrationNDimTypeFromString().

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

Definition at line 92 of file StringUtils.cxx.

Referenced by genie::GVldContext::Decode(), and genie::Spline::SetType().

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