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 | std::vector <std::string> split(std::vector <std::string> &v, const std::string s, const char sep); |
---|
9 | char* str_to_charp(const std::string s); |
---|
10 | |
---|
11 | template <typename T> |
---|
12 | std::string NumberToString ( T Number ) |
---|
13 | { |
---|
14 | std::ostringstream ss; |
---|
15 | ss << Number; |
---|
16 | return ss.str(); |
---|
17 | } |
---|
18 | template <typename T> |
---|
19 | std::string NumberToString ( T Number,int w) |
---|
20 | { |
---|
21 | std::ostringstream ss; |
---|
22 | ss <<std::setfill('0') << std::setw(w) << Number; |
---|
23 | return ss.str(); |
---|
24 | } |
---|
25 | template <typename T> |
---|
26 | T StringToNumber ( const std::string &Text ) |
---|
27 | { |
---|
28 | std::istringstream ss(Text); |
---|
29 | T result; |
---|
30 | return ss >> result ? result : 0; |
---|
31 | } |
---|
32 | |
---|
33 | std::string strtohex(const std::string s); |
---|
34 | std::string hextostr(const std::string s); |
---|
35 | const static std::string ZBEGIN_ = "ZZZ"; |
---|
36 | const static std::string ZEND_ = "YY"; |
---|
37 | |
---|
38 | std::string zstrtohex(const std::string s); |
---|
39 | std::string zhextostr(const std::string s); |
---|
40 | |
---|
41 | std::string gen_random(const int len); |
---|
42 | |
---|
43 | int get_file_contents(std::string &contents,const std::string &filename); |
---|
44 | |
---|
45 | inline std::string trim_right( |
---|
46 | const std::string& s, |
---|
47 | const std::string& delimiters = " \f\n\r\t\v" ) |
---|
48 | { |
---|
49 | size_t p = s.find_last_not_of(delimiters); |
---|
50 | if (p == s.npos) |
---|
51 | return ""; |
---|
52 | return s.substr( 0, p + 1 ); |
---|
53 | } |
---|
54 | |
---|
55 | inline std::string trim_left( |
---|
56 | const std::string& s, |
---|
57 | const std::string& delimiters = " \f\n\r\t\v" ) |
---|
58 | { |
---|
59 | size_t p = s.find_first_not_of(delimiters); |
---|
60 | if (p == s.npos) |
---|
61 | return ""; |
---|
62 | return s.substr(p); |
---|
63 | } |
---|
64 | |
---|
65 | inline std::string trim( |
---|
66 | const std::string& s, |
---|
67 | const std::string& delimiters = " \f\n\r\t\v" ) |
---|
68 | { |
---|
69 | return trim_left( trim_right( s, delimiters ), delimiters ); |
---|
70 | } |
---|
71 | |
---|
72 | int mkdir_p(const std::string &s,mode_t m); |
---|
73 | |
---|
74 | std::string envtostr(const std::string &s); |
---|
75 | #endif |
---|