34 #ifndef CARTOBASE_TYPE_STRING_CONVERSION_H
35 #define CARTOBASE_TYPE_STRING_CONVERSION_H
51 template <
typename T >
56 std::ostringstream stream;
68 inline std::string
toString(
const char&
object )
70 return toString<int>(
object );
78 std::vector< std::string >
split(
const std::string &text,
79 const std::string &sep );
81 std::vector< std::string >
split(
const std::string &text,
82 const std::set<std::string> &sep );
88 std::string
join(
const std::vector< std::string > &pieces,
89 const std::string &sep );
97 std::string
stringStrip(
const std::string& str,
char c =
' ');
100 bool isInt(
const std::string & s );
110 inline std::string
toString(
const unsigned char&
object )
112 return toString<int>(
object );
121 inline std::string
toString(
const signed char&
object )
123 return toString<int>(
object );
132 template <
typename T >
133 void stringTo(
const std::string& value, T& result );
136 template <
typename T >
138 void stringTo(
const std::string& value, T& result )
141 #if __GNUC__ == 2 && __GNUC_MINOR__ - 0 <= 95
143 std::istringstream stream( value.c_str() );
147 std::istringstream stream( value );
184 unsigned long& result );
201 unsigned int& result );
210 unsigned char& result );
219 signed char& result );
231 #ifdef __CHAR_UNSIGNED__
234 reinterpret_cast< unsigned char&
>( result ) );
251 unsigned short& result );
298 bool with_quotes =
true );
bool isInt(const std::string &s)
Does the string represent a valid integer ?
void stringTo< signed char >(const std::string &value, signed char &result)
void stringTo< float >(const std::string &value, float &result)
std::string stringStrip(const std::string &str, char c=' ')
std::vector< std::string > split(const std::string &text, const std::string &sep)
void stringTo< unsigned long >(const std::string &value, unsigned long &result)
void stringTo< char >(const std::string &value, char &result)
std::string toString(const T &object)
void stringTo< bool >(const std::string &value, bool &result)
void stringTo< short >(const std::string &value, short &result)
void stringTo< int >(const std::string &value, int &result)
void stringTo< long >(const std::string &value, long &result)
std::string join(const std::vector< std::string > &pieces, const std::string &sep)
void stringTo(const std::string &value, T &result)
void stringTo< double >(const std::string &value, double &result)
bool isFloat(const std::string &s)
Does the string represent a valid float ?
std::string quotedString(const std::string &s, char *quote=0, bool with_quotes=true)
Quote a string in python style: escape quotes (single and double), depending on a quote character.
std::string stringUpper(const std::string &)
std::string stringLower(const std::string &)
void stringTo< unsigned int >(const std::string &value, unsigned int &result)
void stringTo< unsigned short >(const std::string &value, unsigned short &result)
void stringTo< unsigned char >(const std::string &value, unsigned char &result)
void stringTo< std::string >(const std::string &value, std::string &result)