This file is inspired by the poor quality of string support in STL for what should be trivial capabiltiies, for example setting or appending the ASCII representation of a floating point or integer number to a string. More...
Functions | |
int | Tokenize (std::vector< std::string > &result, const char *input, char delimiter) |
std::string & | append (std::string &s, float f) |
use std streams API to do float conversion to string, then append it. | |
std::string & | append (std::string &s, double f) |
use std streams API to do double conversion to string, then append it. | |
std::string & | append (std::string &s, char c) |
The rest we can handle readily ourselves. | |
std::string & | append (std::string &s, unsigned char c) |
Similar to signed char case, but this time for unsigned. | |
std::string & | append (std::string &s, const char *rhs) |
Now append a full C style NUL terminated string to the std::string. | |
std::string & | append (std::string &s, std::string &rhs) |
Prevent the generic template from picking up std::string. | |
template<typename T > | |
std::string & | append (std::string &s, std::vector< T > v, std::string separator="") |
iterate over the provided vector, appending all elements with an optional separator | |
template<typename T > | |
std::string & | append (std::string &s, T i) |
This template handles the rest of the cases for integral types. | |
std::string & | operator<< (std::string &s, char c) |
std::string & | operator<< (std::string &s, unsigned char c) |
std::string & | operator<< (std::string &s, uint64_t i) |
std::string & | operator<< (std::string &s, int64_t i) |
template<typename T > | |
std::string & | operator<< (std::string &s, T val) |
template<typename S > | |
std::string & | append (std::string &s, std::vector< std::string > v, S delimeter, bool itemize=false) |
template<typename T , typename S > | |
std::string & | append (std::string &s, std::vector< T > v, S delimeter, bool itemize=false) |
This file is inspired by the poor quality of string support in STL for what should be trivial capabiltiies, for example setting or appending the ASCII representation of a floating point or integer number to a string.
This file uses variadic templates to implement a type safe version (subset) of C-library printf.
Therefore, -std=c++0x is a required option on g++
std::string& STLUtilities::append | ( | std::string & | s, | |
T | i | |||
) | [inline] |
This template handles the rest of the cases for integral types.
Not user friendly if you pass in a type T that is for example a std::vector.
Definition at line 128 of file STLUtilities.h.
00129 { 00130 char digits[20]; 00131 char *p = digits; 00132 bool negative = false; 00133 00134 if (i<0) 00135 { 00136 negative = true; 00137 i = -i; 00138 } 00139 00140 do 00141 { 00142 *p++ = '0' + i % 10; 00143 i = i/10; 00144 } 00145 while (i); 00146 00147 if (negative) s += '-'; 00148 00149 do 00150 { 00151 s += *--p; 00152 } 00153 while (p > digits); 00154 00155 return s; 00156 }
std::string& STLUtilities::append | ( | std::string & | s, | |
char | c | |||
) | [inline] |
The rest we can handle readily ourselves.
Unlike std::string operator +, this operator treats c as a character and appends the ASCII character c.
Definition at line 75 of file STLUtilities.h.