StringUtils Class Reference

#include <StringUtils.h>


Detailed Description

Some static methods for string processing.

Definition at line 42 of file StringUtils.h.


Static Public Member Functions

static std::string convertUmlaute (std::string str)
 Converts german "Umlate" to their latin-version.
static std::string escapeXML (const std::string &orig) throw ()
 Replaces the standard escapes by their XML entities.
static std::string prune (std::string str)
 Removes trailing and leading whitechars.
static std::string replace (std::string str, const char *what, const char *by)
static std::string to_lower_case (std::string str)
 Transfers the content to lower case.
static std::string toTimeString (int time)
 Builds a time string (hh:mm:ss) from the given seconds.
static void upper (std::string &str)
 Converts the given string to upper characters.

Static Public Attributes

static std::string emptyString
 An empty string.

Member Function Documentation

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

Converts german "Umlate" to their latin-version.

Definition at line 79 of file StringUtils.cpp.

References replace().

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

00079                                          {
00080     str = replace(str, "ä", "ae");
00081     str = replace(str, "Ä", "Ae");
00082     str = replace(str, "ö", "oe");
00083     str = replace(str, "Ö", "Oe");
00084     str = replace(str, "ü", "ue");
00085     str = replace(str, "Ü", "Ue");
00086     str = replace(str, "ß", "ss");
00087     str = replace(str, "É", "E");
00088     str = replace(str, "é", "e");
00089     str = replace(str, "È", "E");
00090     str = replace(str, "è", "e");
00091     return str;
00092 }

std::string StringUtils::escapeXML ( const std::string &  orig  )  throw () [static]

Replaces the standard escapes by their XML entities.

The strings &, <, >, ", and ' are replaced by &, <, >, ", and '

Parameters:
[in] orig The original string
Returns:
the string with the escaped sequences

Definition at line 139 of file StringUtils.cpp.

References replace().

Referenced by RODFDetectorCon::save(), PCPolyContainer::save(), RODFDetectorCon::saveAsPOIs(), TEST(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), RODFDetectorCon::writeSpeedTrigger(), RODFDetectorCon::writeValidationDetectors(), and MSInductLoop::writeXMLOutput().

00139                                                     {
00140     std::string result = replace(orig, "&", "&amp;");
00141     result = replace(result, ">", "&gt;");
00142     result = replace(result, "<", "&lt;");
00143     result = replace(result, "\"", "&quot;");
00144     return replace(result, "'", "&apos;");
00145 }

std::string StringUtils::prune ( std::string  str  )  [static]

Removes trailing and leading whitechars.

Definition at line 52 of file StringUtils.cpp.

Referenced by getNextNonCommentLine(), OptionsCont::getStringVector(), PCLoaderArcView::load(), NIImporter_ArcView::load(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), readO(), readV(), and TEST().

00052                                 {
00053     int idx = 0;
00054     while (idx<str.length()&&str[idx]<=32) ++idx;
00055     if (idx<str.length()&&idx!=0) {
00056         str = str.substr(idx);
00057     }
00058     idx = str.length() - 1;
00059     while (idx>=0&&str[idx]<=32) --idx;
00060     if (idx!=str.length() - 1) {
00061         str = str.substr(0, idx+1);
00062     }
00063     return str;
00064 }

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 97 of file StringUtils.cpp.

Referenced by convertUmlaute(), escapeXML(), NIImporter_ArcView::load(), RORDGenerator_ODAmounts::parseFlowAmountDef(), and TEST().

00098                                      {
00099     std::string what_tmp(what);
00100     std::string by_tmp(by);
00101     size_t idx = str.find(what);
00102     size_t what_len = what_tmp.length();
00103     size_t by_len = by_tmp.length();
00104     while (idx!=std::string::npos) {
00105         str = str.replace(idx, what_len, by);
00106         idx = str.find(what, idx+by_len-what_len);
00107     }
00108     return str;
00109 }

std::string StringUtils::to_lower_case ( std::string  str  )  [static]

Transfers the content to lower case.

Definition at line 68 of file StringUtils.cpp.

Referenced by NamedColumnsParser::get(), NamedColumnsParser::know(), NIImporter_Vissim::VissimSingleTypeParser::myRead(), NIImporter_Vissim::readContents(), NIImporter_Vissim::VissimSingleTypeParser::readEndSecure(), NamedColumnsParser::reinitMap(), and TEST().

00068                                         {
00069     for (size_t i=0; i<str.length(); i++) {
00070         if (str[i]>='A'&&str[i]<='Z') {
00071             str[i] = str[i] + 'a' - 'A';
00072         }
00073     }
00074     return str;
00075 }

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

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

Definition at line 123 of file StringUtils.cpp.

Referenced by TEST().

00123                                   {
00124     std::ostringstream oss;
00125     char buffer[4];
00126     sprintf(buffer, "%02i:",(time/3600));
00127     oss << buffer;
00128     time=time%3600;
00129     sprintf(buffer, "%02i:",(time/60));
00130     oss << buffer;
00131     time=time%60;
00132     sprintf(buffer, "%02i", time);
00133     oss << buffer;
00134     return oss.str();
00135 }

void StringUtils::upper ( std::string &  str  )  [static]

Converts the given string to upper characters.

Definition at line 113 of file StringUtils.cpp.

Referenced by TEST().

00113                                  {
00114     for (size_t i=0; i<str.length(); i++) {
00115         if (str[i]>='a'&&str[i]<='z') {
00116             str[i] = str[i] - 'a' + 'A';
00117         }
00118     }
00119 }


Field Documentation

std::string StringUtils::emptyString [static]

An empty string.

Definition at line 75 of file StringUtils.h.

Referenced by GUINet::getMicrosimID().


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

Generated on Wed May 5 00:07:00 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6