SUMO - Simulation of Urban MObility
StringUtils.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Some static methods for string processing
20 /****************************************************************************/
21 #ifndef StringUtils_h
22 #define StringUtils_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
44 class StringUtils {
45 public:
47  static std::string prune(const std::string& str);
48 
50  static std::string to_lower_case(std::string str);
51 
53  static std::string latin1_to_utf8(std::string str);
54 
56  static std::string convertUmlaute(std::string str);
57 
60  static std::string replace(std::string str, const char* what,
61  const char* by);
62 
64  static std::string toTimeString(int time);
65 
67  static bool startsWith(const std::string& str, const std::string prefix);
68 
70  static bool endsWith(const std::string& str, const std::string suffix);
71 
81  static std::string escapeXML(const std::string& orig, const bool maskDoubleHyphen = false);
82 
84  static std::string emptyString;
85 
86  // the following methods stem from http://bogomip.net/blog/cpp-url-encoding-and-decoding/
87 
88  static std::string urlEncode(const std::string& url, const std::string encodeWhich = "");
89  static std::string urlDecode(const std::string& encoded);
90 
91  static std::string charToHex(unsigned char c);
92  static unsigned char hexToChar(const std::string& str);
93 
94 };
95 
96 
97 #endif
98 
99 /****************************************************************************/
100 
static unsigned char hexToChar(const std::string &str)
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
Some static methods for string processing.
Definition: StringUtils.h:44
static std::string toTimeString(int time)
Builds a time string (hh:mm:ss) from the given seconds.
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
Definition: StringUtils.cpp:73
static std::string urlEncode(const std::string &url, const std::string encodeWhich="")
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
Definition: StringUtils.cpp:90
static std::string emptyString
An empty string.
Definition: StringUtils.h:84
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.
Definition: StringUtils.cpp:62
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
Definition: StringUtils.cpp:51
static std::string urlDecode(const std::string &encoded)
static std::string charToHex(unsigned char c)