Eclipse SUMO - Simulation of Urban MObility
StringTokenizer Class Reference

#include <StringTokenizer.h>

Public Member Functions

std::string front ()
 returns the first substring without moving the iterator More...
 
std::string get (int pos) const
 returns the item at the given position More...
 
std::set< std::string > getSet ()
 return set of strings More...
 
std::vector< std::string > getVector ()
 return vector of strings More...
 
bool hasNext ()
 returns the information whether further substrings exist More...
 
std::string next ()
 returns the next substring when it exists. Otherwise the behaviour is undefined More...
 
void reinit ()
 reinitialises the internal iterator More...
 
int size () const
 returns the number of existing substrings More...
 
 StringTokenizer ()
 default constructor More...
 
 StringTokenizer (std::string tosplit)
 constructor More...
 
 StringTokenizer (std::string tosplit, int special)
 constructor More...
 
 StringTokenizer (std::string tosplit, std::string token, bool splitAtAllChars=false)
 constructor More...
 
 ~StringTokenizer ()
 destructor More...
 

Static Public Attributes

static const int NEWLINE = -256
 identifier for splitting the given string at all newline characters More...
 
static const int SPACE = 32
 the ascii index of the highest whitespace character More...
 
static const int TAB = 9
 the ascii index of the tab character More...
 
static const int WHITECHARS = -257
 identifier for splitting the given string at all whitespace characters More...
 

Private Types

typedef std::vector< int > SizeVector
 a list of positions/lengths More...
 

Private Member Functions

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 chars given in the second More...
 
void prepareWhitechar (const std::string &tosplit)
 splits the first string at all occurrences of whitechars More...
 

Private Attributes

SizeVector myLengths
 the list of substring lengths More...
 
int myPos
 the current position in the list of substrings More...
 
SizeVector myStarts
 the list of substring starts More...
 
std::string myTosplit
 the string to split More...
 

Detailed Description

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 occurrences of operators as a list of single divider and the string between them will have a length of zero.

Definition at line 60 of file StringTokenizer.h.

Member Typedef Documentation

◆ SizeVector

typedef std::vector<int> StringTokenizer::SizeVector
private

a list of positions/lengths

Definition at line 138 of file StringTokenizer.h.

Constructor & Destructor Documentation

◆ StringTokenizer() [1/4]

StringTokenizer::StringTokenizer ( )

default constructor

Definition at line 45 of file StringTokenizer.cpp.

◆ StringTokenizer() [2/4]

StringTokenizer::StringTokenizer ( std::string  tosplit)

constructor

Parameters
tosplitis the string to split into substrings. If the string between two split positions is empty, it will not be returned.
Note
same as StringTokenizer(tosplit, StringTokenizer.WHITECHARS)

Definition at line 50 of file StringTokenizer.cpp.

References prepareWhitechar().

◆ StringTokenizer() [3/4]

StringTokenizer::StringTokenizer ( std::string  tosplit,
std::string  token,
bool  splitAtAllChars = false 
)

constructor

Note
the first string will be split at the second string's occurrences. 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 56 of file StringTokenizer.cpp.

References prepare().

◆ StringTokenizer() [4/4]

StringTokenizer::StringTokenizer ( std::string  tosplit,
int  special 
)

constructor

Note
When StringTokenizer.NEWLINE is used as second parameter, the string will be split at all occurrences 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 62 of file StringTokenizer.cpp.

References NEWLINE, prepare(), prepareWhitechar(), TAB, and WHITECHARS.

◆ ~StringTokenizer()

StringTokenizer::~StringTokenizer ( )

destructor

Definition at line 85 of file StringTokenizer.cpp.

Member Function Documentation

◆ front()

std::string StringTokenizer::front ( )

returns the first substring without moving the iterator

Definition at line 112 of file StringTokenizer.cpp.

References myLengths, myStarts, and myTosplit.

Referenced by RORouteHandler::addRide().

Here is the caller graph for this function:

◆ get()

std::string StringTokenizer::get ( int  pos) const

◆ getSet()

std::set< std::string > StringTokenizer::getSet ( )

return set of strings

Definition at line 202 of file StringTokenizer.cpp.

References getVector().

Referenced by NIXMLNodesHandler::addJoinCluster(), and LIBSUMO_NAMESPACE::Vehicle::setStopParameter().

Here is the caller graph for this function:

◆ getVector()

std::vector< std::string > StringTokenizer::getVector ( )

return vector of strings

Definition at line 190 of file StringTokenizer.cpp.

References hasNext(), next(), reinit(), and size().

Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NIXMLNodesHandler::addJoinExclusion(), NLHandler::addPhase(), NLHandler::addPredecessorConstraint(), Parameterised::areAttributesValid(), Parameterised::areParametersValid(), NLHandler::beginE3Detector(), CharacteristicMap::CharacteristicMap(), LIBSUMO_NAMESPACE::Person::convertTraCIStage(), GUIApplicationWindow::create(), GUIVehicle::drawAction_drawCarriageClass(), GUIPointOfInterest::drawInnerPOI(), GUIBaseVehicle::drawOnPos(), MSActuatedTrafficLightLogic::evalCustomFunction(), MSActuatedTrafficLightLogic::evalExpression(), MSDevice_SSM::filterByConflictType(), GNEPythonTool::getCommand(), Parameterised::getDoubles(), MSDevice_SSM::getMeasuresAndThresholds(), NIImporter_VISUM::getPermissions(), GNERouteHandler::getPreviousPlanEdge(), getSet(), NWWriter_DlrNavteq::getSinglePostalCode(), MSPModel_JuPedSim::initialize(), NIImporter_OpenStreetMap::EdgesHandler::interpretChangeType(), NIImporter_OpenStreetMap::EdgesHandler::interpretLaneUse(), Parameterised::isParameterValid(), SUMOXMLDefinitions::isValidListOfNetIDs(), PCLoaderDlrNavteq::loadPolyFile(), NWWriter_OpenDrive::mapmatchRoadObjects(), MSActuatedTrafficLightLogic::MSActuatedTrafficLightLogic(), MSDetectorFileOutput::MSDetectorFileOutput(), MSSOTLPolicy5DFamilyStimulus::MSSOTLPolicy5DFamilyStimulus(), MSTriggeredRerouter::MSTriggeredRerouter(), NIImporter_Vissim::NIVissimXMLHandler_Streckendefinition::myStartElement(), NIImporter_OpenStreetMap::EdgesHandler::myStartElement(), NIImporter_OpenStreetMap::RelationHandler::myStartElement(), MSDevice_Bluelight::notifyMove(), GNEAllowVClassesDialog::onCmdReset(), GNEOptionsDialogElements::InputIntVector::onCmdSetOption(), GNEFrameAttributeModules::GenericDataAttributes::onCmdSetParameters(), Distribution_Parameterized::parse(), NLTriggerBuilder::parseAndBuildRerouter(), RGBColor::parseColor(), MSEdge::parseEdgesList(), OptionsCont::relocateFiles(), MSDevice_Bluelight::resetVehicle(), GNEAttributeCarrier::setACParameters(), NBEdge::setOrigID(), NEMALogic::setParameter(), Parameterised::setParametersStr(), string2time(), StringUtils::toVersion(), GNEVehicleTypeDialog::VTypeAttributes::VTypeAttributeRow::updateValue(), OptionsCont::writeConfiguration(), NWWriter_OpenDrive::writeRoadObjects(), and NWWriter_OpenDrive::writeSignals().

◆ hasNext()

◆ next()

std::string StringTokenizer::next ( )

returns the next substring when it exists. Otherwise the behaviour is undefined

Definition at line 98 of file StringTokenizer.cpp.

References myLengths, myPos, myStarts, and myTosplit.

Referenced by NLHandler::addE2Detector(), SUMOVehicleParameter::areInsertionChecksValid(), NLHandler::beginEdgeParsing(), canParseVehicleClasses(), MSDevice_SSM::getMeasuresAndThresholds(), getVector(), PCLoaderVisum::load(), main(), MSRouteHandler::openRouteDistribution(), RORouteHandler::openRouteDistribution(), MSRouteHandler::openVehicleTypeDistribution(), RORouteHandler::openVehicleTypeDistribution(), SUMOVehicleParserHelper::parseAngleTimesMap(), GeomConvHelper::parseBoundaryReporting(), SUMOVehicleParameter::parseInsertionChecks(), NLHandler::parseLanes(), GeomConvHelper::parseShapeReporting(), ODMatrix::parseTimeLine(), parseVehicleClasses(), ODMatrix::readO(), ODMatrix::readTime(), ODMatrix::readV(), NamedColumnsParser::reinitMap(), NIImporter_DlrNavteq::NamesHandler::report(), NIImporter_DlrNavteq::TimeRestrictionsHandler::report(), NIImporter_DlrNavteq::ProhibitionHandler::report(), NIImporter_DlrNavteq::ConnectedLanesHandler::report(), Option_IntVector::set(), Option_StringVector::set(), GNEAttributeCarrier::setACParameters(), GNEVehicleTypeDialog::VTypeAttributes::VTypeAttributeRow::updateValue(), NIImporter_OpenStreetMap::usableType(), and NWWriter_DlrNavteq::writeLinksUnsplitted().

Here is the caller graph for this function:

◆ prepare()

void StringTokenizer::prepare ( const std::string &  tosplit,
const std::string &  token,
bool  splitAtAllChars 
)
private

splits the first string at all occurrences of the second. If the third parameter is true split at all chars given in the second

Definition at line 141 of file StringTokenizer.cpp.

References myLengths, and myStarts.

Referenced by StringTokenizer().

Here is the caller graph for this function:

◆ prepareWhitechar()

void StringTokenizer::prepareWhitechar ( const std::string &  tosplit)
private

splits the first string at all occurrences of whitechars

Definition at line 168 of file StringTokenizer.cpp.

References myLengths, myStarts, and SPACE.

Referenced by StringTokenizer().

Here is the caller graph for this function:

◆ reinit()

void StringTokenizer::reinit ( )

reinitialises the internal iterator

Definition at line 88 of file StringTokenizer.cpp.

References myPos.

Referenced by getVector().

Here is the caller graph for this function:

◆ size()

Field Documentation

◆ myLengths

SizeVector StringTokenizer::myLengths
private

the list of substring lengths

Definition at line 150 of file StringTokenizer.h.

Referenced by front(), get(), next(), prepare(), and prepareWhitechar().

◆ myPos

int StringTokenizer::myPos
private

the current position in the list of substrings

Definition at line 144 of file StringTokenizer.h.

Referenced by hasNext(), next(), and reinit().

◆ myStarts

SizeVector StringTokenizer::myStarts
private

the list of substring starts

Definition at line 147 of file StringTokenizer.h.

Referenced by front(), get(), hasNext(), next(), prepare(), prepareWhitechar(), and size().

◆ myTosplit

std::string StringTokenizer::myTosplit
private

the string to split

Definition at line 141 of file StringTokenizer.h.

Referenced by front(), get(), and next().

◆ NEWLINE

const int StringTokenizer::NEWLINE = -256
static

identifier for splitting the given string at all newline characters

Definition at line 63 of file StringTokenizer.h.

Referenced by GUIPointOfInterest::drawInnerPOI(), GUIBaseVehicle::drawOnPos(), and StringTokenizer().

◆ SPACE

const int StringTokenizer::SPACE = 32
static

the ascii index of the highest whitespace character

Definition at line 69 of file StringTokenizer.h.

Referenced by prepareWhitechar().

◆ TAB

const int StringTokenizer::TAB = 9
static

◆ WHITECHARS

const int StringTokenizer::WHITECHARS = -257
static

The documentation for this class was generated from the following files: