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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A java-style StringTokenizer for c++ (stl)
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 #include <string>
25 #include <vector>
26 #include <set>
27 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
61 public:
63  static const int NEWLINE;
64 
66  static const int WHITECHARS;
67 
69  static const int SPACE;
70 
72  static const int TAB;
73 
74 public:
77 
82  StringTokenizer(std::string tosplit);
83 
90  StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars = false);
91 
100  StringTokenizer(std::string tosplit, int special);
101 
104 
106  void reinit();
107 
109  bool hasNext();
110 
112  std::string next();
113 
115  int size() const;
116 
118  std::string front();
119 
121  std::string get(int pos) const;
122 
124  std::vector<std::string> getVector();
125 
127  std::set<std::string> getSet();
128 
129 private:
131  void prepare(const std::string& tosplit, const std::string& token, bool splitAtAllChars);
132 
134  void prepareWhitechar(const std::string& tosplit);
135 
136 private:
138  typedef std::vector<int> SizeVector;
139 
141  std::string myTosplit;
142 
144  int myPos;
145 
148 
151 };
static const int NEWLINE
identifier for splitting the given string at all newline characters
std::string front()
returns the first substring without moving the iterator
std::set< std::string > getSet()
return set of strings
~StringTokenizer()
destructor
int size() const
returns the number of existing substrings
SizeVector myStarts
the list of substring starts
void reinit()
reinitialises the internal iterator
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
std::string get(int pos) const
returns the item at the given position
std::vector< std::string > getVector()
return vector of strings
std::vector< int > SizeVector
a list of positions/lengths
bool hasNext()
returns the information whether further substrings exist
static const int TAB
the ascii index of the tab character
static const int SPACE
the ascii index of the highest whitespace character
SizeVector myLengths
the list of substring lengths
StringTokenizer()
default constructor
int myPos
the current position in the list of substrings
void prepare(const std::string &tosplit, const std::string &token, bool splitAtAllChars)
splits the first string at all occurrences of the second. If the third parameter is true split at all...
std::string myTosplit
the string to split
void prepareWhitechar(const std::string &tosplit)
splits the first string at all occurrences of whitechars
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined