3 #ifndef ARCLIB_STRINGCONV
4 #define ARCLIB_STRINGCONV
11 #include <arc/Logger.h>
18 extern Logger stringLogger;
25 stringLogger.
msg(
ERROR,
"Empty string");
28 std::stringstream ss(s);
31 stringLogger.
msg(
ERROR,
"Conversion failed: %s", s);
35 stringLogger.
msg(
WARNING,
"Full string not used: %s", s);
45 std::stringstream ss(s);
56 #define stringtoi(A) stringto < int > ((A))
57 #define stringtoui(A) stringto < unsigned int > ((A))
58 #define stringtol(A) stringto < long > ((A))
59 #define stringtoll(A) stringto < long long > ((A))
60 #define stringtoul(A) stringto < unsigned long > ((A))
61 #define stringtoull(A) stringto < unsigned long long > ((A))
62 #define stringtof(A) stringto < float > ((A))
63 #define stringtod(A) stringto < double > ((A))
64 #define stringtold(A) stringto < long double > ((A))
68 bool strtoint(
const std::string& s,
signed int& t,
int base = 10);
72 bool strtoint(
const std::string& s,
unsigned int& t,
int base = 10);
76 bool strtoint(
const std::string& s,
signed long& t,
int base = 10);
80 bool strtoint(
const std::string& s,
unsigned long& t,
int base = 10);
84 bool strtoint(
const std::string& s,
signed long long& t,
int base = 10);
88 bool strtoint(
const std::string& s,
unsigned long long& t,
int base = 10);
92 std::string
tostring(T t,
int width = 0,
int precision = 0) {
95 ss << std::setprecision(precision);
96 ss << std::setw(width) << t;
102 std::string
inttostr(
signed long long t,
int base = 10,
int width = 0);
106 std::string
inttostr(
unsigned long long t,
int base = 10,
int width = 0);
110 inline std::string
inttostr(
signed int t,
int base = 10,
int width = 0) {
111 return inttostr((
signed long long)t,base,width);
116 inline std::string
inttostr(
unsigned int t,
int base = 10,
int width = 0) {
117 return inttostr((
unsigned long long)t,base,width);
122 inline std::string
inttostr(
signed long t,
int base = 10,
int width = 0) {
123 return inttostr((
signed long long)t,base,width);
128 inline std::string
inttostr(
unsigned long t,
int base = 10,
int width = 0) {
129 return inttostr((
unsigned long long)t,base,width);
134 return b ?
"true" :
"false";
139 return s ==
"true" || s ==
"1";
147 if (s ==
"true" || s ==
"1" || s ==
"false" || s ==
"0") {
148 b = (s ==
"true" || s ==
"1");
155 std::string
lower(
const std::string& s);
158 std::string
upper(
const std::string& s);
161 void tokenize(
const std::string& str, std::vector<std::string>& tokens,
162 const std::string& delimiters =
" ",
163 const std::string& start_quotes =
"",
const std::string& end_quotes =
"");
166 void tokenize(
const std::string& str, std::list<std::string>& tokens,
167 const std::string& delimiters =
" ",
168 const std::string& start_quotes =
"",
const std::string& end_quotes =
"");
171 std::string::size_type
get_token(std::string& token,
172 const std::string& str, std::string::size_type pos,
173 const std::string& delimiters =
" ",
174 const std::string& start_quotes =
"",
const std::string& end_quotes =
"");
178 std::string
trim(
const std::string& str,
const char *sep = NULL);
181 std::string
strip(
const std::string& str);
187 std::string
uri_encode(
const std::string& str,
bool encode_slash);
212 #endif // ARCLIB_STRINGCONV