PandaRoot
PndStringSeparator.h
Go to the documentation of this file.
1 
25 #pragma once
26 
27 #include <string>
28 #include <vector>
29 #include "Rtypes.h"
30 
32  public:
33  PndStringSeparator() : fStartPos(0), fStrings(), fInput(), fDelimiter(), fOutput(), fFirstDel(false), fLastDel(false){}
35  explicit PndStringSeparator(std::string AInput, std::string ADelimiter = " ");
36  void SetInput(std::string AInput) { fInput = AInput; }
37  void SetDelimiter(std::string ADelimiter) { fDelimiter = ADelimiter; }
38  void ResetVector() { fStrings.clear(); }
39  std::vector<std::string> GetStringVector(void);
40 
41 
42  std::string Replace(std::string from, std::string to);
43 
44  void Print();
45 
46  protected:
47  void TestFirst()
48  {
49  if (fInput.find_first_of(fDelimiter) == 0)
50  fFirstDel = true;
51  else
52  fFirstDel = false;
53  }
54  void TestLast()
55  {
56  if (fInput.find_last_of(fDelimiter) == fInput.size() - 1)
57  fLastDel = true;
58  else
59  fLastDel = false;
60  }
61  bool GetIfFirst() { return fFirstDel; }
62  bool GetIfLast() { return fLastDel; }
63 
64  private:
65  std::string::size_type fStartPos;
66  std::vector<std::string> fStrings;
67  std::string fInput;
68  std::string fDelimiter;
69  std::string fOutput;
70  std::string GetString(void);
71  bool fFirstDel; // first element in the string was a delimiter
72  bool fLastDel; // last element in the string was a delimiter
73 };
74 
std::string Replace(std::string from, std::string to)
Separates a string into substrings at arbitrary delimiters.
std::vector< std::string > GetStringVector(void)
void SetInput(std::string AInput)
void SetDelimiter(std::string ADelimiter)