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 /****************************************************************************/
17 // A java-style StringTokenizer for c++ (stl)
18 /****************************************************************************/
19 #ifndef StringTokenizer_h
20 #define StringTokenizer_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 
27 #include <string>
28 #include <vector>
29 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
63 public:
65  static const int NEWLINE;
66 
68  static const int WHITECHARS;
69 
71  static const int SPACE;
72 
74  static const int TAB;
75 
76 public:
79 
84  StringTokenizer(std::string tosplit);
85 
92  StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars = false);
93 
102  StringTokenizer(std::string tosplit, int special);
103 
106 
108  void reinit();
109 
111  bool hasNext();
112 
114  std::string next();
115 
117  int size() const;
118 
120  std::string front();
121 
123  std::string get(int pos) const;
124 
126  std::vector<std::string> getVector();
127 
128 private:
130  void prepare(const std::string& tosplit, const std::string& token, bool splitAtAllChars);
131 
133  void prepareWhitechar(const std::string& tosplit);
134 
135 private:
137  typedef std::vector<int> SizeVector;
138 
140  std::string myTosplit;
141 
143  int myPos;
144 
147 
150 };
151 
152 
153 #endif
154 
155 /****************************************************************************/
156 
StringTokenizer::hasNext
bool hasNext()
returns the information whether further substrings exist
Definition: StringTokenizer.cpp:95
StringTokenizer::next
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
Definition: StringTokenizer.cpp:100
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:143
StringTokenizer::~StringTokenizer
~StringTokenizer()
destructor
Definition: StringTokenizer.cpp:87
StringTokenizer::WHITECHARS
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
Definition: StringTokenizer.h:68
StringTokenizer::myTosplit
std::string myTosplit
the string to split
Definition: StringTokenizer.h:140
StringTokenizer::StringTokenizer
StringTokenizer()
default constructor
Definition: StringTokenizer.cpp:47
StringTokenizer::get
std::string get(int pos) const
returns the item at the given position
Definition: StringTokenizer.cpp:125
StringTokenizer::NEWLINE
static const int NEWLINE
identifier for splitting the given string at all newline characters
Definition: StringTokenizer.h:65
StringTokenizer::myLengths
SizeVector myLengths
the list of substring lengths
Definition: StringTokenizer.h:149
StringTokenizer
Definition: StringTokenizer.h:62
StringTokenizer::size
int size() const
returns the number of existing substrings
Definition: StringTokenizer.cpp:138
StringTokenizer::SPACE
static const int SPACE
the ascii index of the highest whitespace character
Definition: StringTokenizer.h:71
StringTokenizer::TAB
static const int TAB
the ascii index of the tab character
Definition: StringTokenizer.h:74
StringTokenizer::SizeVector
std::vector< int > SizeVector
a list of positions/lengths
Definition: StringTokenizer.h:137
StringTokenizer::myStarts
SizeVector myStarts
the list of substring starts
Definition: StringTokenizer.h:146
StringTokenizer::front
std::string front()
returns the first substring without moving the iterator
Definition: StringTokenizer.cpp:114
StringTokenizer::myPos
int myPos
the current position in the list of substrings
Definition: StringTokenizer.h:143
StringTokenizer::getVector
std::vector< std::string > getVector()
return vector of strings
Definition: StringTokenizer.cpp:192
StringTokenizer::prepareWhitechar
void prepareWhitechar(const std::string &tosplit)
splits the first string at all occurences of whitechars
Definition: StringTokenizer.cpp:170
StringTokenizer::reinit
void reinit()
reinitialises the internal iterator
Definition: StringTokenizer.cpp:90