1 | #ifndef WUTILS_H |
---|
2 | #define WUTILS_H |
---|
3 | #include <vector> |
---|
4 | #include <string> |
---|
5 | #include <sstream> |
---|
6 | #include <iomanip> |
---|
7 | #include <sys/types.h> |
---|
8 | #include <list> |
---|
9 | #include <dirent.h> |
---|
10 | std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep); |
---|
11 | char* str_to_charp(const std::string s); |
---|
12 | |
---|
13 | template <typename T> |
---|
14 | std::string NumberToString ( T Number ) |
---|
15 | { |
---|
16 | std::ostringstream ss; |
---|
17 | ss << Number; |
---|
18 | return ss.str(); |
---|
19 | } |
---|
20 | template <typename T> |
---|
21 | std::string NumberToString ( T Number,int w) |
---|
22 | { |
---|
23 | std::ostringstream ss; |
---|
24 | ss <<std::setfill('0') << std::setw(w) << Number; |
---|
25 | return ss.str(); |
---|
26 | } |
---|
27 | template <typename T> |
---|
28 | T StringToNumber ( const std::string &Text ) |
---|
29 | { |
---|
30 | std::istringstream ss(Text); |
---|
31 | T result; |
---|
32 | return ss >> result ? result : 0; |
---|
33 | } |
---|
34 | |
---|
35 | std::string strtohex(const std::string s); |
---|
36 | std::string hextostr(const std::string s); |
---|
37 | const static std::string ZBEGIN_ = "ZZZ"; |
---|
38 | const static std::string ZEND_ = "YY"; |
---|
39 | |
---|
40 | std::string zstrtohex(const std::string s); |
---|
41 | std::string zhextostr(const std::string s); |
---|
42 | |
---|
43 | std::string gen_random(const int len); |
---|
44 | |
---|
45 | int get_file_contents(std::string &contents,const std::string &filename); |
---|
46 | |
---|
47 | inline std::string trim_right( |
---|
48 | const std::string& s, |
---|
49 | const std::string& delimiters = " \f\n\r\t\v" ) |
---|
50 | { |
---|
51 | size_t p = s.find_last_not_of(delimiters); |
---|
52 | if (p == s.npos) |
---|
53 | return ""; |
---|
54 | return s.substr( 0, p + 1 ); |
---|
55 | } |
---|
56 | |
---|
57 | inline std::string trim_left( |
---|
58 | const std::string& s, |
---|
59 | const std::string& delimiters = " \f\n\r\t\v" ) |
---|
60 | { |
---|
61 | size_t p = s.find_first_not_of(delimiters); |
---|
62 | if (p == s.npos) |
---|
63 | return ""; |
---|
64 | return s.substr(p); |
---|
65 | } |
---|
66 | |
---|
67 | inline std::string trim( |
---|
68 | const std::string& s, |
---|
69 | const std::string& delimiters = " \f\n\r\t\v" ) |
---|
70 | { |
---|
71 | return trim_left( trim_right( s, delimiters ), delimiters ); |
---|
72 | } |
---|
73 | |
---|
74 | int mkdir_p(const std::string &s,mode_t m); |
---|
75 | |
---|
76 | std::string envtostr(const std::string &s); |
---|
77 | |
---|
78 | #include <zlib.h> |
---|
79 | |
---|
80 | int get_dir_list(std::list <std::string> &v, |
---|
81 | const std::string &d); |
---|
82 | std::string compress_string(const std::string& str, |
---|
83 | int compressionlevel = Z_BEST_COMPRESSION); |
---|
84 | |
---|
85 | std::string decompress_string(const std::string& str); |
---|
86 | #endif |
---|