PandaRoot
PndStringSeparator.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
37 #pragma once
38 
39 #include <string>
40 #include <vector>
41 #include "Rtypes.h"
42 
44  public:
45  PndStringSeparator() : fStartPos(0), fStrings(), fInput(), fDelimiter(), fOutput(), fFirstDel(false), fLastDel(false){}
47  explicit PndStringSeparator(std::string AInput, std::string ADelimiter = " ");
48  void SetInput(std::string AInput) { fInput = AInput; }
49  void SetDelimiter(std::string ADelimiter) { fDelimiter = ADelimiter; }
50  void ResetVector() { fStrings.clear(); }
51  std::vector<std::string> GetStringVector(void);
52 
53 
54  std::string Replace(std::string from, std::string to);
55 
56  void Print();
57 
58  protected:
59  void TestFirst()
60  {
61  if (fInput.find_first_of(fDelimiter) == 0)
62  fFirstDel = true;
63  else
64  fFirstDel = false;
65  }
66  void TestLast()
67  {
68  if (fInput.find_last_of(fDelimiter) == fInput.size() - 1)
69  fLastDel = true;
70  else
71  fLastDel = false;
72  }
73  bool GetIfFirst() { return fFirstDel; }
74  bool GetIfLast() { return fLastDel; }
75 
76  private:
77  std::string::size_type fStartPos;
78  std::vector<std::string> fStrings;
79  std::string fInput;
80  std::string fDelimiter;
81  std::string fOutput;
82  std::string GetString(void);
83  bool fFirstDel; // first element in the string was a delimiter
84  bool fLastDel; // last element in the string was a delimiter
85 };
86 
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)