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-2022 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 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
60 public:
62  static const int NEWLINE;
63 
65  static const int WHITECHARS;
66 
68  static const int SPACE;
69 
71  static const int TAB;
72 
73 public:
76 
81  StringTokenizer(std::string tosplit);
82 
89  StringTokenizer(std::string tosplit, std::string token, bool splitAtAllChars = false);
90 
99  StringTokenizer(std::string tosplit, int special);
100 
103 
105  void reinit();
106 
108  bool hasNext();
109 
111  std::string next();
112 
114  int size() const;
115 
117  std::string front();
118 
120  std::string get(int pos) const;
121 
123  std::vector<std::string> getVector();
124 
125 private:
127  void prepare(const std::string& tosplit, const std::string& token, bool splitAtAllChars);
128 
130  void prepareWhitechar(const std::string& tosplit);
131 
132 private:
134  typedef std::vector<int> SizeVector;
135 
137  std::string myTosplit;
138 
140  int myPos;
141 
144 
147 };
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
~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 occurences 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 occurences of whitechars
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined