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 
146  SizeVector myStarts;
147 
149  SizeVector myLengths;
150 };
151 
152 
153 #endif
154 
155 /****************************************************************************/
156 
void reinit()
reinitialises the internal iterator
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
std::string myTosplit
the string to split
static const int NEWLINE
identifier for splitting the given string at all newline characters
bool hasNext()
returns the information whether further substrings exist
StringTokenizer()
default constructor
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 ...
~StringTokenizer()
destructor
int size() const
returns the number of existing substrings
SizeVector myLengths
the list of substring lengths
static const int SPACE
the ascii index of the highest whitespace character
std::vector< int > SizeVector
a list of positions/lengths
SizeVector myStarts
the list of substring starts
std::string front()
returns the first substring without moving the iterator
static const int TAB
the ascii index of the tab character
std::vector< std::string > getVector()
return vector of strings
void prepareWhitechar(const std::string &tosplit)
splits the first string at all occurences of whitechars
int myPos
the current position in the list of substrings