SUMO - Simulation of Urban MObility
StringUtils Class Reference

Some static methods for string processing. More...

#include <StringUtils.h>

Collaboration diagram for StringUtils:
Collaboration graph

Static Public Member Functions

static std::string charToHex (unsigned char c)
 
static std::string convertUmlaute (std::string str)
 Converts german "Umlaute" to their latin-version. More...
 
static bool endsWith (const std::string &str, const std::string suffix)
 Checks whether a given string ends with the suffix. More...
 
static std::string escapeXML (const std::string &orig, const bool maskDoubleHyphen=false)
 Replaces the standard escapes by their XML entities. More...
 
static unsigned char hexToChar (const std::string &str)
 
static int hexToInt (const std::string &sData)
 converts a string with a hex value into the integer value described by it by calling the char-type converter More...
 
static std::string latin1_to_utf8 (std::string str)
 Transfers from Latin 1 (ISO-8859-1) to UTF-8. More...
 
static std::string prune (const std::string &str)
 Removes trailing and leading whitechars. More...
 
static std::string replace (std::string str, const char *what, const char *by)
 
static bool startsWith (const std::string &str, const std::string prefix)
 Checks whether a given string starts with the prefix. More...
 
static std::string to_lower_case (std::string str)
 Transfers the content to lower case. More...
 
static bool toBool (const std::string &sData)
 converts a string into the bool value described by it by calling the char-type converter More...
 
static double toDouble (const std::string &sData)
 converts a string into the double value described by it by calling the char-type converter More...
 
static double toDoubleSecure (const std::string &sData, const double def)
 converts a string into the integer value described by it More...
 
static int toInt (const std::string &sData)
 converts a string into the integer value described by it by calling the char-type converter, which More...
 
static int toIntSecure (const std::string &sData, int def)
 converts a string into the integer value described by it More...
 
static long long int toLong (const std::string &sData)
 converts a string into the long value described by it by calling the char-type converter, which More...
 
static std::string toTimeString (int time)
 Builds a time string (hh:mm:ss) from the given seconds. More...
 
static std::string transcode (const XMLCh *const data)
 converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8 More...
 
static std::string transcode (const XMLCh *const data, int length)
 converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8 considering the given length More...
 
static std::string urlDecode (const std::string &encoded)
 
static std::string urlEncode (const std::string &url, const std::string encodeWhich="")
 

Static Public Attributes

static std::string emptyString
 An empty string. More...
 

Detailed Description

Some static methods for string processing.

Definition at line 40 of file StringUtils.h.

Member Function Documentation

◆ charToHex()

std::string StringUtils::charToHex ( unsigned char  c)
static

Definition at line 216 of file StringUtils.cpp.

Referenced by urlEncode().

◆ convertUmlaute()

std::string StringUtils::convertUmlaute ( std::string  str)
static

Converts german "Umlaute" to their latin-version.

Definition at line 86 of file StringUtils.cpp.

References replace().

Referenced by PCLoaderDlrNavteq::loadPolyFile(), NIImporter_Vissim::VissimSingleTypeParser::readName(), and NBEdge::reinit().

◆ endsWith()

bool StringUtils::endsWith ( const std::string &  str,
const std::string  suffix 
)
static

◆ escapeXML()

std::string StringUtils::escapeXML ( const std::string &  orig,
const bool  maskDoubleHyphen = false 
)
static

◆ hexToChar()

unsigned char StringUtils::hexToChar ( const std::string &  str)
static

Definition at line 228 of file StringUtils.cpp.

Referenced by urlDecode().

◆ hexToInt()

int StringUtils::hexToInt ( const std::string &  sData)
static

converts a string with a hex value into the integer value described by it by calling the char-type converter

Exceptions
anEmptyData - exception if the given string is empty
aNumberFormatException - exception when the string does not contain an integer

Definition at line 288 of file StringUtils.cpp.

Referenced by NIImporter_Vissim::NIVissimXMLHandler_Fahrzeugklassendefinition::myEndElement(), and RGBColor::parseColor().

◆ latin1_to_utf8()

std::string StringUtils::latin1_to_utf8 ( std::string  str)
static

Transfers from Latin 1 (ISO-8859-1) to UTF-8.

Definition at line 69 of file StringUtils.cpp.

Referenced by PCLoaderArcView::load().

◆ prune()

◆ replace()

std::string StringUtils::replace ( std::string  str,
const char *  what,
const char *  by 
)
static

Replaces all occurences of the second string by the third string within the first string

Definition at line 104 of file StringUtils.cpp.

Referenced by convertUmlaute(), escapeXML(), NIImporter_ArcView::load(), and GNEInspectorFrame::AttributesEditor::AttributeInput::stripWhitespaceAfterComma().

◆ startsWith()

◆ to_lower_case()

◆ toBool()

◆ toDouble()

double StringUtils::toDouble ( const std::string &  sData)
static

converts a string into the double value described by it by calling the char-type converter

Exceptions
anEmptyData - exception if the given string is empty
aNumberFormatException - exception when the string does not contain a double

Definition at line 312 of file StringUtils.cpp.

Referenced by MSTLLogicControl::WAUTSwitchProcedure_Stretch::adaptLogic(), NIXMLPTHandler::addPTLine(), NBEdgeCont::applyOptions(), MSDevice_Battery::buildVehicleDevices(), MSDevice_Bluelight::buildVehicleDevices(), MSDevice_Example::buildVehicleDevices(), MSFrame::checkOptions(), libsumo::Simulation::findIntermodalRoute(), MSSwarmTrafficLightLogic::getBetaNo(), MSSwarmTrafficLightLogic::getBetaSp(), SUMOSAXAttributesImpl_Cached::getBoundary(), SUMOSAXAttributesImpl_Xerces::getBoundary(), SUMOVTypeParameter::getCFParam(), MSSwarmTrafficLightLogic::getChangePlanProbability(), GNELane::getColorValue(), GUILane::getColorValue(), MFXAddEditTypedTable::getControlForItem(), MSSOTLTrafficLightLogic::getDecayConstant(), MSDevice_SSM::getDetectionRange(), NGNet::getDistribution(), Parameterised::getDouble(), MSDevice_SSM::getExtraTime(), SUMOSAXAttributesImpl_Cached::getFloat(), SUMOSAXAttributesImpl_Binary::getFloat(), SUMOSAXAttributesImpl_Xerces::getFloat(), MSDevice::getFloatParam(), MSSwarmTrafficLightLogic::getForgettingCox(), MSSwarmTrafficLightLogic::getGammaNo(), MSSwarmTrafficLightLogic::getGammaSp(), MSSOTLTrafficLightLogic::getInputSensorsLength(), SUMOVTypeParameter::getJMParam(), SUMOVTypeParameter::getLCParam(), MSSwarmTrafficLightLogic::getLearningCox(), MSDevice_SSM::getMeasuresAndThresholds(), NIImporter_VISUM::getNamedFloat(), MSSOTLTrafficLightLogic::getOutputSensorsLength(), MSSwarmTrafficLightLogic::getPheroMaxVal(), SUMOSAXAttributesImpl_Cached::getShape(), SUMOSAXAttributesImpl_Xerces::getShape(), MSSOTLTrafficLightLogic::getSpeedThreshold(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereichDef(), MSSwarmTrafficLightLogic::getThetaInit(), MSSwarmTrafficLightLogic::getThetaMax(), MSSwarmTrafficLightLogic::getThetaMin(), getTurningDefaults(), MSTriggeredRerouter::getWeight(), NIImporter_VISUM::getWeightedFloat(), PushButtonLogic::init(), SigmoidLogic::init(), MSSwarmTrafficLightLogic::init(), LandmarkLookupTable< E, V >::LandmarkLookupTable(), PCLoaderVisum::load(), PCLoaderDlrNavteq::loadPolyFile(), main(), MSActuatedTrafficLightLogic::MSActuatedTrafficLightLogic(), MSDelayBasedTrafficLightLogic::MSDelayBasedTrafficLightLogic(), MSSOTLPolicy::MSSOTLPolicy(), NIImporter_Vissim::NIVissimXMLHandler_Streckendefinition::myEndElement(), NIImporter_ITSUMO::Handler::myEndElement(), NIImporter_Vissim::NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition::myEndElement(), GUISettingsHandler::myStartElement(), NIImporter_OpenStreetMap::NodesHandler::myStartElement(), NIImporter_OpenStreetMap::EdgesHandler::myStartElement(), GUIDialog_ViewSettings::onCmdEditTable(), NIVissimSingleTypeParser_Laengenverteilungsdefinition::parse(), NIVissimSingleTypeParser_Streckendefinition::parse(), NIVissimSingleTypeParser_Simdauer::parse(), NIVissimSingleTypeParser_Geschwindigkeitsverteilungsdefinition::parse(), NIVissimSingleTypeParser_Zeitenverteilungsdefinition::parse(), NIVissimSingleTypeParser_Verbindungsdefinition::parse(), Distribution_Parameterized::parse(), GNEAttributeCarrier::parse(), NIImporter_VISUM::parse_Edges(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_Point(), SUMOVehicleParameter::parseArrivalPos(), SUMOVehicleParameter::parseArrivalPosLat(), SUMOVehicleParameter::parseArrivalSpeed(), GeomConvHelper::parseBoundaryReporting(), RGBColor::parseColor(), SUMOVehicleParameter::parseDepartPos(), SUMOVehicleParameter::parseDepartPosLat(), SUMOVehicleParameter::parseDepartSpeed(), GeomConvHelper::parseShapeReporting(), GUISettingsHandler::parseSizeSettings(), GUISettingsHandler::parseTextSettings(), ODMatrix::parseTimeLine(), RODFDetFlowLoader::read(), ODMatrix::readFactor(), ODMatrix::readO(), ODMatrix::readV(), NIImporter_DlrNavteq::readVersion(), Option_Float::set(), Option_FloatVector::set(), MSFrame::setMSGlobals(), MSDevice_Battery::setParameter(), MSDevice_DriverState::setParameter(), MSPersonDevice_Routing::setParameter(), MSLCM_LC2013::setParameter(), MSDevice_Bluelight::setParameter(), MSDevice_Example::setParameter(), MSLCM_SL2015::setParameter(), MSDevice_ToC::setParameter(), MSDevice_Routing::setParameter(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::stretchLogic(), string2time(), toDoubleSecure(), and RODFDetector::writeEmitterDefinition().

◆ toDoubleSecure()

double StringUtils::toDoubleSecure ( const std::string &  sData,
const double  def 
)
static

converts a string into the integer value described by it

Returns
the default value if the data is empty

Definition at line 332 of file StringUtils.cpp.

References toDouble().

Referenced by MSRouteHandler::openRouteDistribution().

◆ toInt()

int StringUtils::toInt ( const std::string &  sData)
static

converts a string into the integer value described by it by calling the char-type converter, which

Exceptions
anEmptyData - exception if the given string is empty
NumberFormatException- exception when the string does not contain an integer

Definition at line 246 of file StringUtils.cpp.

References toLong(), and toString().

Referenced by NIXMLEdgesHandler::addSplit(), MFXAddEditTypedTable::getControlForItem(), OutputDevice::getDevice(), MSTLLogicControl::WAUTSwitchProcedure::getGSPValue(), SUMOSAXAttributesImpl_Cached::getInt(), SUMOSAXAttributesImpl_Xerces::getInt(), NBEdge::getLaneIndexFromLaneID(), NINavTeqHelper::getLaneNumber(), MSSwarmTrafficLightLogic::getMaxCongestionDuration(), MSSOTLRequestPolicy::getMinDecisionalPhaseDuration(), MSSOTLTrafficLightLogic::getMode(), MSSwarmTrafficLightLogic::getReinforcementMode(), NINavTeqHelper::getSpeed(), MSSOTLTrafficLightLogic::getThreshold(), MSSwarmTrafficLightLogic::init(), NBHelpers::interpretLaneID(), PCLoaderVisum::load(), NIImporter_Vissim::NIVissimXMLHandler_Streckendefinition::myEndElement(), NIImporter_ITSUMO::Handler::myEndElement(), NIImporter_Vissim::NIVissimXMLHandler_Fahrzeugklassendefinition::myEndElement(), GUISettingsHandler::myStartElement(), NIImporter_MATSim::EdgesHandler::myStartElement(), NIImporter_OpenStreetMap::EdgesHandler::myStartElement(), NIVissimSingleTypeParser_Kantensperrung::parse(), NIVissimSingleTypeParser_Knotendefinition::parse(), NIVissimSingleTypeParser_Streckendefinition::parse(), NIVissimSingleTypeParser_VWunschentscheidungsdefinition::parse(), NIVissimSingleTypeParser_Fahrzeugklassendefinition::parse(), NIVissimSingleTypeParser_Fahrzeugtypdefinition::parse(), NIVissimSingleTypeParser_Verbindungsdefinition::parse(), GNEAttributeCarrier::parse(), NIImporter_VISUM::parse_EdgePolys(), NIImporter_VISUM::parse_Edges(), NIImporter_VISUM::parse_Lanes(), NIImporter_VISUM::parse_LanesConnections(), NIImporter_VISUM::parse_Types(), SUMOVehicleParameter::parseArrivalLane(), NIImporter_Vissim::VissimSingleTypeParser::parseAssignedVehicleTypes(), RGBColor::parseColor(), SUMOVehicleParameter::parseDepartLane(), NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parsePos(), ODMatrix::parseSingleTime(), NIImporter_DlrNavteq::readDate(), NIImporter_Vissim::VissimSingleTypeParser::readExtEdgePointDef(), ODMatrix::readO(), ODMatrix::readV(), NIImporter_DlrNavteq::EdgesHandler::report(), NIImporter_DlrNavteq::ConnectedLanesHandler::report(), Option_Integer::set(), Option_IntVector::set(), NIVissimConflictArea::setPriorityRegulation(), MSSOTLE2Sensors::setVehicleWeigths(), GUIMainWindow::setWindowSizeAndPos(), toIntSecure(), and RODFDetector::writeEmitterDefinition().

◆ toIntSecure()

int StringUtils::toIntSecure ( const std::string &  sData,
int  def 
)
static

converts a string into the integer value described by it

Returns
the default value if the data is empty

Definition at line 256 of file StringUtils.cpp.

References toInt().

Referenced by RODFDetectorHandler::myStartElement(), and NIXMLConnectionsHandler::parseDeprecatedLaneDefinition().

◆ toLong()

long long int StringUtils::toLong ( const std::string &  sData)
static

◆ toTimeString()

std::string StringUtils::toTimeString ( int  time)
static

Builds a time string (hh:mm:ss) from the given seconds.

Definition at line 122 of file StringUtils.cpp.

◆ transcode() [1/2]

◆ transcode() [2/2]

std::string StringUtils::transcode ( const XMLCh *const  data,
int  length 
)
static

converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8 considering the given length

Exceptions
EmptyDataif the given pointer is 0

Definition at line 361 of file StringUtils.cpp.

◆ urlDecode()

std::string StringUtils::urlDecode ( const std::string &  encoded)
static

Definition at line 199 of file StringUtils.cpp.

References hexToChar().

Referenced by OptionsCont::relocateFiles().

◆ urlEncode()

std::string StringUtils::urlEncode ( const std::string &  url,
const std::string  encodeWhich = "" 
)
static

Definition at line 174 of file StringUtils.cpp.

References charToHex().

Referenced by Option_FileName::getValueString().

Field Documentation

◆ emptyString

std::string StringUtils::emptyString
static

An empty string.

Definition at line 80 of file StringUtils.h.

Referenced by MSPerson::getNextEdge(), and GUIGlObject::getParentName().


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