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 <costas.andreopoulos stfc.ac.uk> University of Liverpool & STFC Rutherford Appleton Lab

January 12, 2004

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

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 85 of file StringUtils.cxx.

References elec2geo::pos.

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

86 {
87 // filter out from 'input' all characters that can be found in 'filt_elements'
88 
89  string filtered_string = input;
91 
92  while( (pos = filtered_string.find_first_of(
93  filt_elements, pos)) != string::npos )
94  filtered_string.erase(pos,1);
95  return filtered_string;
96 }
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
string genie::utils::str::IntAsString ( int  i)

Definition at line 35 of file StringUtils.cxx.

References MECModelEnuComparisons::i.

36 {
37  ostringstream os;
38  os << i;
39  return os.str();
40 }
string genie::utils::str::RemoveSuccessiveSpaces ( string  input)

Definition at line 58 of file StringUtils.cxx.

References FilterString(), and elec2geo::pos.

Referenced by TrimSpaces().

59 {
60 // this method trims white space that may be found within an expression...
61 // eg. "stop pressing the spacebar" -> "stop pressing the spacebar"
62 
63  string trimmed = input;
64 
66 
67  while( (pos = trimmed.find_first_of(" ", pos)) != string::npos ) {
68  if( trimmed[++pos] == ' ' ) trimmed.erase(pos--,1);
69  }
70  return FilterString("\n",trimmed);
71 }
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
string FilterString(string filt, string input)
Definition: StringUtils.cxx:85
void genie::utils::str::ReplaceStringInPlace ( string &  subject,
const string &  search,
const string &  replace 
)

Definition at line 73 of file StringUtils.cxx.

References elec2geo::pos.

75 {
76 // Searches the string "input" for "search" and replaces this with "replace"
77  size_t pos = 0;
78  while ((pos = subject.find(search, pos)) != std::string::npos) {
79  subject.replace(pos, search.length(), replace);
80  // move to end of replaced string
81  pos += replace.length();
82  }
83 }
vector< string > genie::utils::str::Split ( string  input,
string  delim 
)

Definition at line 42 of file StringUtils.cxx.

Referenced by genie::AlgConfigPool::AddBasicParameter(), 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(), GenerateEventsAtFixedInitState(), genie::utils::system::GenieMajorVrsNum(), genie::utils::system::GenieMinorVrsNum(), genie::utils::system::GenieRevisVrsNum(), GetAlgorithms(), genie::utils::system::GetAllFilesInPath(), GetCommandLineArgs(), genie::utils::xml::GetDoubleArray(), genie::flux::GDk2NuFluxXMLHelper::GetDoubleVector(), genie::flux::GNuMIFluxXMLHelper::GetDoubleVector(), genie::utils::xml::GetIntArray(), genie::flux::GDk2NuFluxXMLHelper::GetIntVector(), genie::flux::GNuMIFluxXMLHelper::GetIntVector(), GetNeutrinoCodes(), GetPDGCodeListFromString(), GetTargetCodes(), genie::utils::xml::GetXMLFilePath(), genie::NtpMCJobConfig::Load(), genie::flux::GJPARCNuFlux::LoadBeamSimData(), genie::BaryonResonanceDecayer::LoadConfig(), genie::Decayer::LoadConfig(), main(), genie::utils::app_init::MesgThresholds(), genie::flux::GFlavorMap::ParseFixedfracString(), ParseFluxFileConfig(), ParseFluxHst(), genie::flux::GFlavorMap::ParseMapString(), genie::geometry::GeomVolSelectorBasic::ParseSelection(), genie::Messenger::SetPrioritiesFromXmlFile(), and genie::flux::GDk2NuFluxXMLHelper::~GDk2NuFluxXMLHelper().

43 {
44 // split a string of 'delimiter' separated values and return each string
45 // part as a vector<string> element.
46 
47  vector<string> string_parts;
48 
49  while(input.find_first_of(delimiter) < input.length()) {
50 
51  string_parts.push_back( input.substr(0, input.find_first_of(delimiter)) );
52  input = input.substr(input.find_first_of(delimiter)+1, input.length());
53  }
54  string_parts.push_back(input);
55  return string_parts;
56 }
string genie::utils::str::ToLower ( string  input)

Definition at line 104 of file StringUtils.cxx.

References MECModelEnuComparisons::i.

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

105 {
106  for(unsigned int i=0; i<input.size(); i++) input[i] = tolower(input[i]);
107  return input;
108 }
string genie::utils::str::ToUpper ( string  input)

Definition at line 98 of file StringUtils.cxx.

References MECModelEnuComparisons::i.

Referenced by genie::GVldContext::Decode().

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

Definition at line 24 of file StringUtils.cxx.

References RemoveSuccessiveSpaces().

Referenced by CalcTotalXSec(), genie::flux::GFlavorMap::Config(), Configure(), GenerateEvent(), genie::utils::xml::GetAttribute(), genie::utils::xml::GetDoubleArray(), genie::flux::GDk2NuFluxXMLHelper::GetDoubleVector(), genie::flux::GNuMIFluxXMLHelper::GetDoubleVector(), genie::utils::xml::GetIntArray(), genie::flux::GDk2NuFluxXMLHelper::GetIntVector(), genie::flux::GNuMIFluxXMLHelper::GetIntVector(), genie::GSimFiles::LoadFromFile(), genie::XSecSplineList::LoadFromXml(), genie::PathLengthList::LoadFromXml(), genie::Spline::LoadFromXmlFile(), genie::AlgConfigPool::LoadMasterConfig(), genie::flux::GDk2NuFluxXMLHelper::LoadParamSet(), genie::flux::GNuMIFluxXMLHelper::LoadParamSet(), genie::AlgConfigPool::LoadRegistries(), genie::flux::GDk2NuFluxXMLHelper::ParseBeamDir(), genie::flux::GNuMIFluxXMLHelper::ParseBeamDir(), genie::flux::GFlavorMap::ParseFixedfracString(), genie::flux::GDk2NuFluxXMLHelper::ParseRotSeries(), genie::flux::GNuMIFluxXMLHelper::ParseRotSeries(), genie::flux::GDk2NuFluxXMLHelper::ParseWindowSeries(), genie::flux::GNuMIFluxXMLHelper::ParseWindowSeries(), genie::FermiMomentumTablePool::ParseXMLTables(), genie::geometry::PathSegmentList::Print(), genie::Messenger::SetPrioritiesFromXmlFile(), genie::utils::xml::TrimSpaces(), and genie::flux::GDk2NuFluxXMLHelper::~GDk2NuFluxXMLHelper().

25 {
26  if( input.find_first_not_of(" \n") != 0)
27  input.erase( 0, input.find_first_not_of(" \n") );
28 
29  if( input.find_last_not_of(" \n") != input.length() )
30  input.erase( input.find_last_not_of(" \n")+1, input.length() );
31 
32  return RemoveSuccessiveSpaces(input);
33 }
string RemoveSuccessiveSpaces(string input)
Definition: StringUtils.cxx:58