Eclipse SUMO - Simulation of Urban MObility
StringTokenizer.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A java-style StringTokenizer for c++ (stl)
17 /****************************************************************************/
18 #ifndef StringTokenizer_h
19 #define StringTokenizer_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 
26 #include <string>
27 #include <vector>
28 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
62 public:
64  static const int NEWLINE;
65 
67  static const int WHITECHARS;
68 
70  static const int SPACE;
71 
73  static const int TAB;
74 
75 public:
78 
83  StringTokenizer(std::string tosplit);
84 
91  StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars = false);
92 
101  StringTokenizer(std::string tosplit, int special);
102 
105 
107  void reinit();
108 
110  bool hasNext();
111 
113  std::string next();
114 
116  int size() const;
117 
119  std::string front();
120 
122  std::string get(int pos) const;
123 
125  std::vector<std::string> getVector();
126 
127 private:
129  void prepare(const std::string& tosplit, const std::string& token, bool splitAtAllChars);
130 
132  void prepareWhitechar(const std::string& tosplit);
133 
134 private:
136  typedef std::vector<int> SizeVector;
137 
139  std::string myTosplit;
140 
142  int myPos;
143 
146 
149 };
150 
151 
152 #endif
153 
154 /****************************************************************************/
155 
StringTokenizer::hasNext
bool hasNext()
returns the information whether further substrings exist
Definition: StringTokenizer.cpp:94
StringTokenizer::next
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
Definition: StringTokenizer.cpp:99
StringTokenizer::prepare
void prepare(const std::string &tosplit, const std::string &token, bool splitAtAllChars)
splits the first string at all occurences of the second. If the third parameter is true split at all ...
Definition: StringTokenizer.cpp:142
StringTokenizer::~StringTokenizer
~StringTokenizer()
destructor
Definition: StringTokenizer.cpp:86
StringTokenizer::WHITECHARS
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
Definition: StringTokenizer.h:67
StringTokenizer::myTosplit
std::string myTosplit
the string to split
Definition: StringTokenizer.h:139
StringTokenizer::StringTokenizer
StringTokenizer()
default constructor
Definition: StringTokenizer.cpp:46
StringTokenizer::get
std::string get(int pos) const
returns the item at the given position
Definition: StringTokenizer.cpp:124
StringTokenizer::NEWLINE
static const int NEWLINE
identifier for splitting the given string at all newline characters
Definition: StringTokenizer.h:64
StringTokenizer::myLengths
SizeVector myLengths
the list of substring lengths
Definition: StringTokenizer.h:148
StringTokenizer
Definition: StringTokenizer.h:61
StringTokenizer::size
int size() const
returns the number of existing substrings
Definition: StringTokenizer.cpp:137
StringTokenizer::SPACE
static const int SPACE
the ascii index of the highest whitespace character
Definition: StringTokenizer.h:70
StringTokenizer::TAB
static const int TAB
the ascii index of the tab character
Definition: StringTokenizer.h:73
StringTokenizer::SizeVector
std::vector< int > SizeVector
a list of positions/lengths
Definition: StringTokenizer.h:136
StringTokenizer::myStarts
SizeVector myStarts
the list of substring starts
Definition: StringTokenizer.h:145
StringTokenizer::front
std::string front()
returns the first substring without moving the iterator
Definition: StringTokenizer.cpp:113
StringTokenizer::myPos
int myPos
the current position in the list of substrings
Definition: StringTokenizer.h:142
StringTokenizer::getVector
std::vector< std::string > getVector()
return vector of strings
Definition: StringTokenizer.cpp:191
StringTokenizer::prepareWhitechar
void prepareWhitechar(const std::string &tosplit)
splits the first string at all occurences of whitechars
Definition: StringTokenizer.cpp:169
StringTokenizer::reinit
void reinit()
reinitialises the internal iterator
Definition: StringTokenizer.cpp:89