|
SUMO - Simulation of Urban MObility
|
#include <StringTokenizer.h>
Public Member Functions | |
| std::string | front () |
| std::string | get (size_t pos) const |
| std::vector< std::string > | getVector () |
| bool | hasNext () |
| std::string | next () |
| void | reinit () |
| size_t | size () const |
| StringTokenizer (std::string tosplit, std::string token, bool splitAtAllChars=false) | |
| constructor the first string will be split at the second string's occurences. If the optional third parameter is true, the string will be split whenever a char from the second string occurs. If the string between two split positions is empty, it will nevertheless be returned. | |
| StringTokenizer () | |
| StringTokenizer (std::string tosplit) | |
| constructor same as StringTokenizer(tosplit, StringTokenizer.WHITECHARS) tosplit is the string to split into substrings. If the string between two split positions is empty, it will not be returned. | |
| StringTokenizer (std::string tosplit, int special) | |
| constructor When StringTokenizer.NEWLINE is used as second parameter, the string will be split at all occurences of a newline character (0x0d / 0x0a) When StringTokenizer.WHITECHARS is used as second parameter, the string will be split at all characters below 0x20 (SPACE) All other ints specified as second parameter are casted int o a char at which the string will be splitted. | |
| ~StringTokenizer () | |
Static Public Attributes | |
| static const int | NEWLINE = -256 |
| static const int | SPACE = 32 |
| static const int | WHITECHARS = -257 |
Private Types | |
| typedef std::vector< size_t > | SizeVector |
Private Member Functions | |
| void | prepare (const std::string &tosplit, const std::string &token, bool splitAtAllChars) |
| void | prepareWhitechar (const std::string &tosplit) |
Private Attributes | |
| SizeVector | myLengths |
| size_t | myPos |
| SizeVector | myStarts |
| std::string | myTosplit |
StringTokenizer A class similar to the StringTokenizer from Java. It splits a string at the given string or character (or one of the special cases NEWLINE or WHITECHAR) and allows to iterate over the so generated substrings.
The normal usage is like this:
StringTokenizer st(CString("This is a line"), ' '); while(st.hasNext()) cout << st.next() << endl;
This would generate the output:
This is a line
There is something to know about the behaviour: When using WHITECHAR, a list of whitechars occuring in the string to split is regarded as a single divider. All other parameter will use multiple occurences of operators as a list of single divider and the string between them will have a length of zero.
Definition at line 67 of file StringTokenizer.h.
typedef std::vector<size_t> StringTokenizer::SizeVector [private] |
a list of positions/lengths
Definition at line 140 of file StringTokenizer.h.
| StringTokenizer::StringTokenizer | ( | ) | [inline] |
default constructor
Definition at line 81 of file StringTokenizer.h.
| StringTokenizer::StringTokenizer | ( | std::string | tosplit | ) |
constructor same as StringTokenizer(tosplit, StringTokenizer.WHITECHARS) tosplit is the string to split into substrings. If the string between two split positions is empty, it will not be returned.
Definition at line 52 of file StringTokenizer.cpp.
References prepareWhitechar().
| StringTokenizer::StringTokenizer | ( | std::string | tosplit, |
| std::string | token, | ||
| bool | splitAtAllChars = false |
||
| ) |
constructor the first string will be split at the second string's occurences. If the optional third parameter is true, the string will be split whenever a char from the second string occurs. If the string between two split positions is empty, it will nevertheless be returned.
Definition at line 58 of file StringTokenizer.cpp.
References prepare().
| StringTokenizer::StringTokenizer | ( | std::string | tosplit, |
| int | special | ||
| ) |
constructor When StringTokenizer.NEWLINE is used as second parameter, the string will be split at all occurences of a newline character (0x0d / 0x0a) When StringTokenizer.WHITECHARS is used as second parameter, the string will be split at all characters below 0x20 (SPACE) All other ints specified as second parameter are casted int o a char at which the string will be splitted.
Definition at line 64 of file StringTokenizer.cpp.
References NEWLINE, prepare(), prepareWhitechar(), and WHITECHARS.
| StringTokenizer::~StringTokenizer | ( | ) |
destructor
Definition at line 84 of file StringTokenizer.cpp.
| std::string StringTokenizer::front | ( | ) |
returns the first substring without moving the iterator
Definition at line 107 of file StringTokenizer.cpp.
| std::string StringTokenizer::get | ( | size_t | pos | ) | const |
returns the item at the given position
Definition at line 117 of file StringTokenizer.cpp.
| std::vector< std::string > StringTokenizer::getVector | ( | ) |
Definition at line 181 of file StringTokenizer.cpp.
References hasNext(), next(), reinit(), and size().
Referenced by NIXMLNodesHandler::addJoinCluster(), OptionsCont::getStringVector(), PCLoaderDlrNavteq::loadPolyFile(), MSRouteHandler::myStartElement(), MSEdge::parseEdgesList(), NIImporter_DlrNavteq::TrafficlightsHandler::report(), and NIImporter_DlrNavteq::EdgesHandler::report().
| bool StringTokenizer::hasNext | ( | ) |
returns the information whether further substrings exist
Definition at line 90 of file StringTokenizer.cpp.
References myPos, and myStarts.
Referenced by NLDetectorBuilder::createEdgeLaneMeanData(), getVector(), NIImporter_OpenStreetMap::insertEdge(), RORDLoader_SUMOBase::myCharacters(), ROJTRTurnDefLoader::myStartElement(), MSRouteHandler::openRouteDistribution(), MSRouteHandler::openVehicleTypeDistribution(), NLHandler::parseLanes(), GeomConvHelper::parseShapeReporting(), SUMOSAXAttributes::parseStringVector(), parseVehicleClasses(), readV(), NamedColumnsParser::reinitMap(), and Option_IntVector::set().
| std::string StringTokenizer::next | ( | ) |
returns the next substring when it exists. Otherwise the behaviour is undefined
Definition at line 94 of file StringTokenizer.cpp.
References myLengths, myPos, myStarts, and myTosplit.
Referenced by NLDetectorBuilder::createEdgeLaneMeanData(), NLHandler::getLanesFromIndices(), getVector(), NIImporter_OpenStreetMap::insertEdge(), PCLoaderVisum::load(), RORDLoader_SUMOBase::myCharacters(), ROJTRTurnDefLoader::myStartElement(), NIImporter_MATSim::EdgesHandler::myStartElement(), MSRouteHandler::openRouteDistribution(), MSRouteHandler::openVehicleTypeDistribution(), GeomConvHelper::parseBoundaryReporting(), RGBColor::parseColor(), NIXMLConnectionsHandler::parseDeprecatedLaneDefinition(), NLHandler::parseLanes(), GeomConvHelper::parseShapeReporting(), SUMOSAXAttributes::parseStringVector(), parseTimeLine(), parseVehicleClasses(), readO(), readTime(), readV(), NamedColumnsParser::reinitMap(), OptionsCont::relocateFiles(), NIImporter_DlrNavteq::EdgesHandler::report(), and Option_IntVector::set().
| void StringTokenizer::prepare | ( | const std::string & | tosplit, |
| const std::string & | token, | ||
| bool | splitAtAllChars | ||
| ) | [private] |
splits the first string at all occurences of the second. If the third parameter is true split at all chars given in the second
Definition at line 134 of file StringTokenizer.cpp.
References myLengths, and myStarts.
Referenced by StringTokenizer().
| void StringTokenizer::prepareWhitechar | ( | const std::string & | tosplit | ) | [private] |
splits the first string at all occurences of whitechars
Definition at line 160 of file StringTokenizer.cpp.
References myLengths, myStarts, and SPACE.
Referenced by StringTokenizer().
| void StringTokenizer::reinit | ( | ) |
reinitialises the internal iterator
Definition at line 86 of file StringTokenizer.cpp.
References myPos.
Referenced by getVector().
| size_t StringTokenizer::size | ( | ) | const |
returns the number of existing substrings
Definition at line 130 of file StringTokenizer.cpp.
References myStarts.
Referenced by NLHandler::getLanesFromIndices(), getVector(), NamedColumnsParser::hasFullDefinition(), NIImporter_MATSim::EdgesHandler::myStartElement(), GeomConvHelper::parseBoundaryReporting(), RGBColor::parseColor(), NIXMLConnectionsHandler::parseDeprecatedLaneDefinition(), parseTimeLine(), and readO().
SizeVector StringTokenizer::myLengths [private] |
the list of substring lengths
Definition at line 152 of file StringTokenizer.h.
Referenced by front(), get(), next(), prepare(), and prepareWhitechar().
size_t StringTokenizer::myPos [private] |
the current position in the list of substrings
Definition at line 146 of file StringTokenizer.h.
SizeVector StringTokenizer::myStarts [private] |
the list of substring starts
Definition at line 149 of file StringTokenizer.h.
Referenced by front(), get(), hasNext(), next(), prepare(), prepareWhitechar(), and size().
std::string StringTokenizer::myTosplit [private] |
the string to split
Definition at line 143 of file StringTokenizer.h.
const int StringTokenizer::NEWLINE = -256 [static] |
identifier for splitting the given string at all newline characters
Definition at line 70 of file StringTokenizer.h.
Referenced by StringTokenizer().
const int StringTokenizer::SPACE = 32 [static] |
the ascii index of the highest whitespace character
Definition at line 77 of file StringTokenizer.h.
Referenced by prepareWhitechar().
const int StringTokenizer::WHITECHARS = -257 [static] |
identifier for splitting the given string at all whitespace characters
Definition at line 74 of file StringTokenizer.h.
Referenced by ROJTRTurnDefLoader::myStartElement(), readO(), readTime(), readV(), NIImporter_DlrNavteq::TrafficlightsHandler::report(), NIImporter_DlrNavteq::EdgesHandler::report(), and StringTokenizer().