28 if (!fmt || (strlen(fmt)==0))
return;
31 int length(256), result(0);
34 if (buffer)
delete [] buffer;
35 buffer =
new char [length];
38 result = vsnprintf(buffer, length, fmt, args);
41 if (result<0) length *= 2;
else
42 if (result>=length) length = result + 1;
else
51 if (!fmt || (strlen(fmt)==0))
return std::string(
"");
54 int length(256), result(0);
57 if (buffer)
delete [] buffer;
58 buffer =
new char [length];
61 result = vsnprintf(buffer, length, fmt, args);
64 if (result<0) length *= 2;
else
65 if (result>=length) length = result + 1;
else
69 std::string s(buffer);
78 unsigned long mult = prec<=0 ? 10 : 1;
79 if (sz < 0x1000LU) select = 1;
else
80 if (sz < 0x100000LU*mult) select = 2;
else
81 if (sz < 0x40000000LU*mult) select =3;
else select = 4;
96 return dabc::format(
"%*.*f MB", prec+2, prec, sz/1024./1024.);
101 return dabc::format(
"%*.*f GB", prec+2, prec, sz/1024./1024./1024.);
110 unsigned long mult = prec<=0 ? 10 : 1;
111 if (num < 10000LU) select = 1;
else
112 if (num < 1000000LU*mult) select = 2;
else
113 if (num < 1000000000LU*mult) select = 3;
else select = 4;
144 if ((val==0) || (res==0))
return false;
146 while (*val==
' ') val++;
147 if (*val==0)
return false;
148 if ((strlen(val)>2) && (val[0]==
'0') && ((val[1]==
'x') || (val[1]==
'X'))) {
150 if (sscanf(val+2,
"%x", &ures) == 1) {
157 if (strpbrk(val,
".,eE")!=0)
return false;
159 return sscanf(val,
"%d", res) == 1;
164 if ((val==0) || (res==0))
return false;
166 while (*val==
' ') val++;
167 if (*val==0)
return false;
169 if ((strlen(val)>2) && (val[0]==
'0') && ((val[1]==
'x') || (val[1]==
'X'))) {
170 long unsigned ures = 0;
171 if (sscanf(val+2,
"%lx", &ures) == 1) {
178 if (strpbrk(val,
".,eE")!=0)
return false;
180 return sscanf(val,
"%ld", res) == 1;
186 if ((val==0) || (res==0))
return false;
188 while (*val==
' ') val++;
189 if (*val==0)
return false;
191 if ((strlen(val)>2) && (val[0]==
'0') && ((val[1]==
'x') || (val[1]==
'X'))) {
192 return sscanf(val+2,
"%x", res) == 1;
195 if (strpbrk(val,
".,eE")!=0)
return false;
197 return sscanf(val,
"%u", res) == 1;
202 if ((val==0) || (res==0))
return false;
204 while (*val==
' ') val++;
205 if (*val==0)
return false;
207 if ((strlen(val)>2) && (val[0]==
'0') && ((val[1]==
'x') || (val[1]==
'X'))) {
208 return sscanf(val+2,
"%lx", res) == 1;
211 if (strpbrk(val,
".,eE")!=0)
return false;
213 return sscanf(val,
"%lu", res) == 1;
218 if ((val==0) || (res==0))
return false;
220 if (sscanf(val,
"%lf", res) == 1)
return true;
224 if (
str_to_uint(val, &ures)) { *res = ures;
return true; }
231 if ((val==0) || (res==0))
return false;
232 if (strcmp(val,
xmlTrueValue)==0) { *res =
true;
return true; }
233 if (strcmp(val,
xmlFalseValue)==0) { *res =
false;
return true; }
237 std::string
dabc::replace_all(
const std::string &str,
const std::string &match,
const std::string &replace)
239 if (match.empty())
return str;
241 std::string res = str;
242 size_t last = 0, pos = 0;
244 while ((pos = res.find(match, last)) != std::string::npos) {
245 res.erase(pos, match.length());
246 res.insert(pos, replace);
247 last = pos + replace.length();
255 char *loc = setlocale(LC_NUMERIC, NULL);
256 if (loc && (strcmp(loc,
"C") != 0)) {
258 setlocale(LC_NUMERIC,
"C");
265 setlocale(LC_NUMERIC, fPrev.c_str());
std::string replace_all(const std::string &str, const std::string &match, const std::string &replace)
Replace all matches in the string.
bool str_to_uint(const char *val, unsigned *res)
Convert string to unsigned integer value One could use hexadecimal (in form 0xabc100) or decimal form...
void formats(std::string &sbuf, const char *fmt,...)
bool str_to_double(const char *val, double *res)
Convert string to double value.
std::string format(const char *fmt,...)
std::string size_to_str(unsigned long sz, int prec=1, int select=0)
Convert size to string of form like 4.2 GB or 3.7 MB.
std::string number_to_str(unsigned long num, int prec=1, int select=0)
Convert number to string of form like 4.2G or 3.7M.
const char * xmlTrueValue
bool str_to_lint(const char *val, long *res)
Convert string to long integer value.
bool str_to_luint(const char *val, long unsigned *res)
Convert string to long unsigned integer value One could use hexadecimal (in form 0xabc100) or decimal...
const char * xmlFalseValue
bool str_to_bool(const char *val, bool *res)
Convert string to bool value.
bool str_to_int(const char *val, int *res)
Convert string to integer value.