14 #ifndef __INLUCDED__SCOPIRA_TOOL_UTIL_H_ 15 #define __INLUCDED__SCOPIRA_TOOL_UTIL_H_ 20 #include <scopira/tool/array.h> 21 #include <scopira/tool/platform.h> 22 #include <scopira/tool/export.h> 36 inline intptr_t
ptr_to_int(
const void *ptr) {
return reinterpret_cast<intptr_t
>(ptr); }
43 inline C *
int_to_ptr(intptr_t x) {
return reinterpret_cast<C*
>(x); }
48 inline void *
int_to_void(intptr_t x) {
return reinterpret_cast<void*
>(x); }
56 inline std::string
bool_to_string(
bool val){
if( val )
return "true";
else return "false"; };
63 inline void int_to_string(
bool val, std::string &out) {
if( val ) out=
"true";
else out=
"false"; }
87 SCOPIRA_EXPORT
int int_to_string(
int i,
char *out,
int buflen);
102 SCOPIRA_EXPORT
bool string_to_int(
const std::string &s,
int &outint);
132 SCOPIRA_EXPORT
bool string_to_long(
const std::string &s,
long &outlong);
162 SCOPIRA_EXPORT
bool string_to_size_t(
const std::string &s,
size_t &outsize_t);
192 SCOPIRA_EXPORT
bool string_to_int64_t(
const std::string &s, int64_t &outint64_t);
247 SCOPIRA_EXPORT
bool string_to_double(
const std::string &s,
double &outdouble);
273 SCOPIRA_EXPORT
void uppercase(
const std::string& s, std::string& upper);
280 SCOPIRA_EXPORT std::string
uppercase(
const std::string& s);
288 SCOPIRA_EXPORT
void lowercase(
const std::string& s, std::string& lower);
295 SCOPIRA_EXPORT std::string
lowercase(
const std::string& s);
307 SCOPIRA_EXPORT std::string
pad_left(
const std::string &s,
int width,
char padchar =
' ');
310 SCOPIRA_EXPORT
void impl_cstring_to_fixed_array_impl(
const char *in,
size_t srclen,
char *out,
size_t N)
throw();
319 { impl_cstring_to_fixed_array_impl(src.c_str(), src.size(), out.c_array(), N); }
327 { impl_cstring_to_fixed_array_impl(in, in?strlen(in):0, out.c_array(), N); }
339 SCOPIRA_EXPORT
bool split_char(
const std::string &src,
char split, std::string &left_out, std::string &right_out);
350 SCOPIRA_EXPORT std::string
filename_number(
const std::string &fname,
int num);
358 SCOPIRA_EXPORT
void trim_left(std::string& str);
374 template<
class container>
377 std::string::size_type start = 0;
378 std::string::size_type pos;
384 while ((pos = src.find(substr, start)) != std::string::npos) {
386 result.push_back(src.substr(start, pos-start));
388 start = pos + substr.length();
391 if (start != src.length())
392 result.push_back(src.substr(start, src.length()-start));
405 template<
class container>
406 void string_tokenize(
const std::string& src, container& result,
const std::string& delimiters =
" \t\n")
408 const std::string::size_type len = src.length();
409 std::string::size_type i = 0;
415 i = src.find_first_not_of(delimiters, i);
416 if (i == std::string::npos)
420 std::string::size_type j = src.find_first_of(delimiters, i);
423 if (j == std::string::npos) {
424 result.push_back(src.substr(i));
427 result.push_back(src.substr(i, j-i));
450 ( (x & 0xFF) << 8 ) |
451 ( (x & 0xFF00) >> 8 );
463 ( (x & 0xFF) << 24 ) |
464 ( (x & 0xFF00) << 8 ) |
465 ( (x & 0xFF0000) >> 8 ) |
466 ( (x & 0xFF000000) >> 24 );
476 ( (x & 0xFFll) << (8*7) ) |
477 ( (x & 0xFF00ll) << (8*5) ) |
478 ( (x & 0xFF0000ll) << (8*3) ) |
479 ( (x & 0xFF000000ll) << 8 ) |
480 ( (x & 0xFF00000000ll) >> 8 ) |
481 ( (x & 0xFF0000000000ll) >> (8*3) ) |
482 ( (x & 0xFF000000000000ll) >> (8*5) ) |
483 ( (x & 0xFF00000000000000ll) >> (8*7) );
494 ( (x & 0xFFull) << (8*7) ) |
495 ( (x & 0xFF00ull) << (8*5) ) |
496 ( (x & 0xFF0000ull) << (8*3) ) |
497 ( (x & 0xFF000000ull) << 8 ) |
498 ( (x & 0xFF00000000ull) >> 8 ) |
499 ( (x & 0xFF0000000000ull) >> (8*3) ) |
500 ( (x & 0xFF000000000000ull) >> (8*5) ) |
501 ( (x & 0xFF00000000000000ull) >> (8*7) );
513 char *I =
reinterpret_cast<char*
>(&x);
514 char *O =
reinterpret_cast<char*
>(&ret);
531 char *I =
reinterpret_cast<char*
>(&x);
532 char *O =
reinterpret_cast<char*
>(&ret);
548 template <
class ITER>
553 template <
class ITER>
556 for (; head != tail; ++head)
Definition: archiveflow.h:20