FairRoot/PandaRoot
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PndStringSeparator Class Reference

#include <PndStringSeparator.h>

Public Member Functions

 PndStringSeparator ()
 
 ~PndStringSeparator ()
 
 PndStringSeparator (std::string AInput, std::string ADelimiter=" ")
 
void SetInput (std::string AInput)
 
void SetDelimiter (std::string ADelimiter)
 
void ResetVector ()
 
std::vector< std::string > GetStringVector (void)
 
void TestFirst ()
 
void TestLast ()
 
bool GetIfFirst ()
 
bool GetIfLast ()
 
std::string Replace (std::string from, std::string to)
 
void Print ()
 

Private Member Functions

std::string GetString (void)
 

Private Attributes

std::string::size_type fStartPos
 
std::vector< std::string > fStrings
 
std::string fInput
 
std::string fDelimiter
 
std::string fOutput
 
bool fFirstDel
 
bool fLastDel
 

Detailed Description


     PndStringSeparator

     Version 1.0
       by
     Tobias Stockmanns

Seperates an input string into substrings and stores them in a string vector. The seperation criteria is a string of characters. If no delimiters are given the default delimiter " " is used.

Example: std::vector<std::string> fOutput TPndStringVector fInput("Column:Row Type: Test ", ": "); fOutput = fInput.GetStringVector();

fOutput[0] = "Column" fOutput[1] = "Row" fOutput[2] = "Type" fOutput[3] = "Test"

Definition at line 30 of file PndStringSeparator.h.

Constructor & Destructor Documentation

PndStringSeparator::PndStringSeparator ( )
inline

Definition at line 33 of file PndStringSeparator.h.

33 :fStartPos(0), fStrings(), fInput(), fDelimiter(), fOutput(), fFirstDel(false),fLastDel(false){};
std::vector< std::string > fStrings
std::string::size_type fStartPos
PndStringSeparator::~PndStringSeparator ( )
inline

Definition at line 34 of file PndStringSeparator.h.

34 {};
PndStringSeparator::PndStringSeparator ( std::string  AInput,
std::string  ADelimiter = " " 
)

Definition at line 6 of file PndStringSeparator.cxx.

7  :fStartPos(0), fStrings(), fInput(AInput), fDelimiter(ADelimiter), fOutput(), fFirstDel(false),fLastDel(false)
8 {}
std::vector< std::string > fStrings
std::string::size_type fStartPos

Member Function Documentation

bool PndStringSeparator::GetIfFirst ( )
inline

Definition at line 42 of file PndStringSeparator.h.

References fFirstDel.

Referenced by Replace().

42 {return fFirstDel;}
bool PndStringSeparator::GetIfLast ( )
inline

Definition at line 43 of file PndStringSeparator.h.

References fLastDel.

Referenced by Replace().

43 {return fLastDel;}
std::string PndStringSeparator::GetString ( void  )
private

Definition at line 11 of file PndStringSeparator.cxx.

References fDelimiter, fInput, fStartPos, and pos.

Referenced by GetStringVector().

12 {
13  std::string::size_type pos;
14  std::string aString;
15  pos = fInput.find_first_of(fDelimiter.c_str(), fStartPos);
16  if (pos-fStartPos == 0) { //first value at fStartPos is a fDelimiter
17  fStartPos += 1;
18  return "";
19  }
20 
21  else if (pos != std::string::npos){ // a delimiter was found after fStartPos
22  aString = fInput.substr(fStartPos, pos-fStartPos);
23  fStartPos = pos + 1;
24  return aString;
25  }
26 
27  else { //no delimiter was found after fStartPos
28  aString = fInput.substr(fStartPos, pos-fStartPos);
29  fStartPos = pos;
30  return aString;
31  }
32 }
TVector3 pos
std::string::size_type fStartPos
std::vector< std::string > PndStringSeparator::GetStringVector ( void  )

Definition at line 35 of file PndStringSeparator.cxx.

References fStartPos, fStrings, GetString(), ResetVector(), TestFirst(), and TestLast().

Referenced by PndGeoHandling::DiveDownToFillSensNamePar(), PndMvdDigiAna::Exec(), PndLmdNoiseProducer::FillSensorLists(), PndMvdNoiseProducer::FillSensorLists(), PndFileNameCreator::GetFileName(), PndFileNameCreator::GetPath(), Replace(), PndFileNameCreator::TruncateFileName(), and PndFileNameCreator::TruncateInitial().

36 {
37  fStartPos = 0;
38  std::string value;
39 
40  ResetVector();
41  TestFirst();
42  TestLast();
43  while (fStartPos != std::string::npos){
44  value = GetString();
45  if (value.length() > 0)
46  fStrings.push_back(value);
47  }
48  return fStrings;
49 }
std::vector< std::string > fStrings
std::string::size_type fStartPos
std::string GetString(void)
void PndStringSeparator::Print ( )

Definition at line 68 of file PndStringSeparator.cxx.

References fInput, fStrings, and i.

Referenced by PndFileNameCreator::GetPath().

69 {
70  std::cout << "PndStringSeparator for: " << fInput << std::endl;
71  for (UInt_t i = 0; i < fStrings.size(); i++)
72  std::cout << i << ": " << fStrings[i] << std::endl;
73 }
Int_t i
Definition: run_full.C:25
std::vector< std::string > fStrings
std::string PndStringSeparator::Replace ( std::string  from,
std::string  to 
)

Definition at line 51 of file PndStringSeparator.cxx.

References fDelimiter, GetIfFirst(), GetIfLast(), GetStringVector(), i, and SetDelimiter().

52 {
53  std::string olddel = fDelimiter;
54  SetDelimiter(from);
55  std::stringstream result;
56  std::vector<std::string> strVector = GetStringVector();
57  if (GetIfFirst()) result << to;
58  result << strVector[0];
59  for (unsigned int i = 1; i < strVector.size(); i++){
60  result << to << strVector[i];
61  }
62  if(GetIfLast()) result << to;
63  fDelimiter = olddel;
64  //std::cout << "New String: " << result.str() << std::endl;
65  return result.str();
66 }
std::vector< std::string > GetStringVector(void)
Int_t i
Definition: run_full.C:25
void SetDelimiter(std::string ADelimiter)
void PndStringSeparator::ResetVector ( )
inline

Definition at line 38 of file PndStringSeparator.h.

References fStrings.

Referenced by GetStringVector().

38 {fStrings.clear();};
std::vector< std::string > fStrings
void PndStringSeparator::SetDelimiter ( std::string  ADelimiter)
inline

Definition at line 37 of file PndStringSeparator.h.

References fDelimiter.

Referenced by Replace().

37 {fDelimiter = ADelimiter;};
void PndStringSeparator::SetInput ( std::string  AInput)
inline

Definition at line 36 of file PndStringSeparator.h.

References fInput.

36 {fInput = AInput;};
void PndStringSeparator::TestFirst ( )
inline

Definition at line 40 of file PndStringSeparator.h.

References fDelimiter, fFirstDel, and fInput.

Referenced by GetStringVector().

40 {if(fInput.find_first_of(fDelimiter)==0) fFirstDel=true; else fFirstDel=false;}
void PndStringSeparator::TestLast ( )
inline

Definition at line 41 of file PndStringSeparator.h.

References fDelimiter, fInput, and fLastDel.

Referenced by GetStringVector().

41 {if(fInput.find_last_of(fDelimiter)==fInput.size()-1) fLastDel = true; else fLastDel = false;}

Member Data Documentation

std::string PndStringSeparator::fDelimiter
private

Definition at line 51 of file PndStringSeparator.h.

Referenced by GetString(), Replace(), SetDelimiter(), TestFirst(), and TestLast().

bool PndStringSeparator::fFirstDel
private

Definition at line 54 of file PndStringSeparator.h.

Referenced by GetIfFirst(), and TestFirst().

std::string PndStringSeparator::fInput
private

Definition at line 50 of file PndStringSeparator.h.

Referenced by GetString(), Print(), SetInput(), TestFirst(), and TestLast().

bool PndStringSeparator::fLastDel
private

Definition at line 55 of file PndStringSeparator.h.

Referenced by GetIfLast(), and TestLast().

std::string PndStringSeparator::fOutput
private

Definition at line 52 of file PndStringSeparator.h.

std::string::size_type PndStringSeparator::fStartPos
private

Definition at line 48 of file PndStringSeparator.h.

Referenced by GetString(), and GetStringVector().

std::vector<std::string> PndStringSeparator::fStrings
private

Definition at line 49 of file PndStringSeparator.h.

Referenced by GetStringVector(), Print(), and ResetVector().


The documentation for this class was generated from the following files: