libutil++  1.9.3
 All Classes Functions Variables
String.h
1 /*
2 ** libutil++
3 ** $Id: String.h 1911 2017-09-02 17:37:35Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__util__String_H__
10 #define __libutilxx__sella__util__String_H__
11 
12 #include "../../common.h"
13 #include "RegexException.h"
14 #include "CompressionException.h"
15 #include "CryptException.h"
16 #include "Crypt.h"
17 
18 #include <stdarg.h>
19 
20 #include <set>
21 #include <list>
22 #include <vector>
23 #include <string>
24 
25 #include <boost/regex.hpp>
26 
27 namespace sella {
28  namespace util {
29  class String;
30  }
31  namespace variant {
32  class Variant;
33  }
34 }
35 
37  public:
38  typedef const boost::regex_constants::syntax_option_type REFlag;
39  typedef const boost::regex_constants::match_flag_type MatchFlag;
40 
41  static REFlag& DefaultREFlags(void) { static REFlag v = boost::regex_constants::normal; return v; }
42  static MatchFlag& DefaultMatchFlags(void) { static MatchFlag v = boost::regex_constants::match_default; return v; }
43 
44  static const int DefaultLevel = 6; /* Gzip */
45  static const std::string& DefaultSalt(void) { static std::string v(CRYPT_SALT_DEF); return v; }
46 
47  enum Algo : uint8_t { Auto, Zlib, LZ4, Gzip };
48 
49  static const std::string& AlphaNumericMixedCase(void) { static std::string v("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); return v; }
50  static const std::string& AlphaNumbericUpperCase(void) { static std::string v("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); return v; }
51  static const std::string& AlphaNumbericLowerCase(void) { static std::string v("0123456789abcdefghijklmnopqrstuvwxyz"); return v; }
52  static const std::string& Whitespace(void) { static std::string v(" \t\r\n\v\f"); return v; }
53  static const std::string& Delim(void) { static std::string v(" ,;:"); return v; }
54  static const std::string& nil(void) { static std::string v; return v; }
55  static const char* RadixLookup(void) { static char v[] = "0123456789abcdef"; return v; }
56 
57  public:
58  static std::string sprintf(const char* format, ...) throw ();
59  static std::string sprintf(const std::string &format, ...) throw ();
60  static std::string vsprintf(const char* format, va_list args) throw ();
61  static std::string vsprintf(const std::string &format, va_list args) throw ();
62 
63  static int strcmp(const std::string &a, const std::string &b) throw (); /* Case sensitive: 0 == match, >0 if a > b, <0 if b > a */
64  static int strcasecmp(const std::string &a, const std::string &b) throw (); /* Case insensitive: 0 == match, >0 if a > b, <0 if b > a */
65 
66  static int strncmp(const std::string &a, const std::string &b, size_t len) throw (); /* Case sensitive: 0 == match, >0 if a > b, <0 if b > a */
67  static int strncasecmp(const std::string &a, const std::string &b, size_t len) throw (); /* Case insensitive: 0 == match, >0 if a > b, <0 if b > a */
68 
69  static bool str_imatch(const std::string &a, const std::string &b) throw ();
70 
71  static std::string substr_replace(const std::string &src, const std::string &search, const std::string &replace = nil(), bool global = true) throw ();
72  static std::string& substr_replace(std::string &src, const std::string &search, const std::string &replace = nil(), bool global = true) throw ();
73 
74  static std::string substr_ireplace(const std::string &src, const std::string &search, const std::string &replace = nil(), bool global = true) throw ();
75  static std::string& substr_ireplace(std::string &src, const std::string &search, const std::string &replace = nil(), bool global = true) throw ();
76 
77  static std::string escape_percent(const std::string &src) throw ();
78  static std::string escape(const std::string &src, const std::string &chars = "\"", const std::string &escape = "\\") throw ();
79 
80  static std::string regex_replace(const std::string &src, const boost::regex &regex, const std::string &replace = nil(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
81  static std::string regex_replace(const std::string &src, const std::string &regex, const std::string &replace = nil(), REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
82  static std::string& regex_replace(std::string &src, const boost::regex &regex, const std::string &replace = nil(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
83  static std::string& regex_replace(std::string &src, const std::string &regex, const std::string &replace = nil(), REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
84 
85  static std::string regex_ireplace(const std::string &src, const boost::regex &regex, const std::string &replace = nil(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
86  static std::string regex_ireplace(const std::string &src, const std::string &regex, const std::string &replace = nil(), REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
87  static std::string& regex_ireplace(std::string &src, const boost::regex &regex, const std::string &replace = nil(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
88  static std::string& regex_ireplace(std::string &src, const std::string &regex, const std::string &replace = nil(), REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
89 
90  static bool regex_match(const std::string &src, const boost::regex &regex, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* match: Full string match */
91  static bool regex_match(const std::string &src, const std::string &regex, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
92  static bool regex_match(const std::string &src, const boost::regex &regex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
93  static bool regex_match(const std::string &src, const std::string &regex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
94  static bool regex_match(const std::string &src, const boost::regex &regex, std::string &match, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
95  static bool regex_match(const std::string &src, const std::string &regex, std::string &match, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
96  static bool regex_match(const std::string &src, const boost::regex &regex, std::vector<std::string> &matches, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
97  static bool regex_match(const std::string &src, const std::string &regex, std::vector<std::string> &matches, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
98 
99  static bool regex_imatch(const std::string &src, const boost::regex &regex, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* match: Full string match */
100  static bool regex_imatch(const std::string &src, const std::string &regex, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
101  static bool regex_imatch(const std::string &src, const boost::regex &regex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
102  static bool regex_imatch(const std::string &src, const std::string &regex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
103  static bool regex_imatch(const std::string &src, const boost::regex &regex, std::string &match, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
104  static bool regex_imatch(const std::string &src, const std::string &regex, std::string &match, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
105  static bool regex_imatch(const std::string &src, const boost::regex &regex, std::vector<std::string> &matches, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
106  static bool regex_imatch(const std::string &src, const std::string &regex, std::vector<std::string> &matches, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
107 
108  static bool regex_search(const std::string &src, const boost::regex &regex, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* search: Partial string match */
109  static bool regex_search(const std::string &src, const std::string &regex, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
110  static bool regex_search(const std::string &src, const boost::regex &regex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
111  static bool regex_search(const std::string &src, const std::string &regex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
112  static bool regex_search(const std::string &src, const boost::regex &regex, std::string &match, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
113  static bool regex_search(const std::string &src, const std::string &regex, std::string &match, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
114  static bool regex_search(const std::string &src, const boost::regex &regex, std::vector<std::string> &matches, bool global = true, bool subexp = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
115  static bool regex_search(const std::string &src, const std::string &regex, std::vector<std::string> &matches, bool global = true, bool subexp = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
116  static bool regex_search(const std::string &src, const boost::regex &regex, std::set<std::string> &matches, bool global = true, bool subexp = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
117  static bool regex_search(const std::string &src, const std::string &regex, std::set<std::string> &matches, bool global = true, bool subexp = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
118 
119  static bool regex_search_sub(const std::string &src, const boost::regex &regex, std::vector<std::string> &matches, bool global = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* Only returns subexpressions */
120  static bool regex_search_sub(const std::string &src, const std::string &regex, std::vector<std::string> &matches, bool global = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
121  static bool regex_search_sub(const std::string &src, const boost::regex &regex, std::set<std::string> &matches, bool global = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* Only returns subexpressions */
122  static bool regex_search_sub(const std::string &src, const std::string &regex, std::set<std::string> &matches, bool global = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
123 
124  static bool regex_isearch(const std::string &src, const boost::regex &regex, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* search: Partial string match */
125  static bool regex_isearch(const std::string &src, const std::string &regex, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
126  static bool regex_isearch(const std::string &src, const boost::regex &regex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
127  static bool regex_isearch(const std::string &src, const std::string &regex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
128  static bool regex_isearch(const std::string &src, const boost::regex &regex, std::string &match, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
129  static bool regex_isearch(const std::string &src, const std::string &regex, std::string &match, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
130  static bool regex_isearch(const std::string &src, const boost::regex &regex, std::vector<std::string> &matches, bool global = true, bool subexp = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
131  static bool regex_isearch(const std::string &src, const std::string &regex, std::vector<std::string> &matches, bool global = true, bool subexp = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
132  static bool regex_isearch(const std::string &src, const boost::regex &regex, std::set<std::string> &matches, bool global = true, bool subexp = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
133  static bool regex_isearch(const std::string &src, const std::string &regex, std::set<std::string> &matches, bool global = true, bool subexp = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
134 
135  static bool regex_isearch_sub(const std::string &src, const boost::regex &regex, std::vector<std::string> &matches, bool global = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* Only returns subexpressions */
136  static bool regex_isearch_sub(const std::string &src, const std::string &regex, std::vector<std::string> &matches, bool global = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
137  static bool regex_isearch_sub(const std::string &src, const boost::regex &regex, std::set<std::string> &matches, bool global = true, MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException); /* Only returns subexpressions */
138  static bool regex_isearch_sub(const std::string &src, const std::string &regex, std::set<std::string> &matches, bool global = true, REFlag reFlags = DefaultREFlags(), MatchFlag mFlags = DefaultMatchFlags()) throw (RegexException);
139 
140  static std::vector<std::string> regex_split(const std::string &str, const boost::regex &delim, bool empty = true, size_t limit = -1) throw (RegexException);
141  static std::vector<std::string> regex_split(const std::string &str, const std::string &regex, bool empty = true, size_t limit = -1, REFlag reFlags = DefaultREFlags()) throw (RegexException);
142 
143  static std::vector<std::string> regex_isplit(const std::string &str, const boost::regex &delim, bool empty = true, size_t limit = -1) throw (RegexException);
144  static std::vector<std::string> regex_isplit(const std::string &str, const std::string &regex, bool empty = true, size_t limit = -1, REFlag reFlags = DefaultREFlags()) throw (RegexException);
145 
146  static std::vector<std::string> split(const std::string &str, const std::string &delim = Delim(), bool exact = false, bool empty = true, size_t limit = -1) throw ();
147  static std::vector<std::string> split(const std::string &str, char delim, bool empty = true, size_t limit = -1) throw ();
148  static std::vector<std::string> split(const std::string &str, const boost::regex &delim, bool empty = true, size_t limit = -1) throw ();
149 
150  static std::vector<std::string> split_csv(const std::string &line, const std::string &delim, bool empty = true, size_t limit = -1) throw ();
151 
152  static std::string join(const std::vector<std::string> &src, const std::string &delim, char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
153  static std::string join(const std::vector<std::string> &src, char delim = ',', char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
154  static std::string join(const std::list<std::string> &src, const std::string &delim, char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
155  static std::string join(const std::list<std::string> &src, char delim = ',', char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
156  static std::string join(const std::set<std::string> &src, const std::string &delim, char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
157  static std::string join(const std::set<std::string> &src, char delim = ',', char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
158  static std::string join(const std::vector<variant::Variant> &src, const std::string &delim, char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
159  static std::string join(const std::vector<variant::Variant> &src, char delim = ',', char quote = '\0', const std::string &empty = nil(), const std::string &lbr = nil(), const std::string &rbr = nil(), size_t threshold = 1) throw ();
160 
161  static std::string trim(const std::string &str, const std::string &space = Whitespace()) throw ();
162  static std::string trim(const std::string &str, char space) throw ();
163  static std::string& trim(std::string &str, const std::string &space = Whitespace()) throw ();
164  static std::string& trim(std::string &str, char space) throw ();
165  static std::string rtrim(const std::string &str, const std::string &space = Whitespace()) throw ();
166  static std::string rtrim(const std::string &str, char space) throw ();
167  static std::string& rtrim(std::string &str, const std::string &space = Whitespace()) throw ();
168  static std::string& rtrim(std::string &str, char space) throw ();
169  static std::string ltrim(const std::string &str, const std::string &space = Whitespace()) throw ();
170  static std::string ltrim(const std::string &str, char space) throw ();
171  static std::string& ltrim(std::string &str, const std::string &space = Whitespace()) throw ();
172  static std::string& ltrim(std::string &str, char space) throw ();
173 
174  static std::string lower(const std::string &src) throw ();
175  static std::string& lower(std::string &src) throw ();
176  static std::string upper(const std::string &src) throw ();
177  static std::string& upper(std::string &src) throw ();
178  static std::string ucfirst(const std::string &src) throw ();
179  static std::string& ucfirst(std::string &src) throw ();
180  static std::string ucword(const std::string &src) throw ();
181  static std::string& ucword(std::string &src) throw ();
182 
183  static std::string itoa(int64_t src, int base = 10) throw ();
184  static std::string itoa(uint64_t src, int base = 10) throw ();
185 #ifdef __LP64__
186  static std::string itoa(int src, int base = 10) throw () { return itoa((int64_t) src, base); }
187  static std::string itoa(unsigned int src, int base = 10) throw () { return itoa((int64_t) src, base); }
188  static std::string itoa(long long src, int base = 10) throw () { return itoa((int64_t) src, base); }
189  static std::string itoa(unsigned long long src, int base = 10) throw () { return itoa((uint64_t) src, base); }
190 #else
191  static std::string itoa(long src, int base = 10) throw () { return itoa((int64_t) src, base); }
192  static std::string itoa(unsigned long src, int base = 10) throw () { return itoa((uint64_t) src, base); }
193 #endif
194  static char* itoa(int64_t src, char *dst, size_t &len, int base = 10) throw ();
195  static char* itoa(uint64_t src, char *dst, size_t &len, int base = 10) throw ();
196 #ifdef __LP64__
197  static char* itoa(int src, char *dst, size_t &len, int base = 10) throw () { return itoa((int64_t) src, dst, len, base); }
198  static char* itoa(unsigned int src, char *dst, size_t &len, int base = 10) throw () { return itoa((uint64_t) src, dst, len, base); }
199  static char* itoa(long long src, char *dst, size_t &len, int base = 10) throw () { return itoa((int64_t) src, dst, len, base); }
200  static char* itoa(unsigned long long src, char *dst, size_t &len, int base = 10) throw () { return itoa((uint64_t) src, dst, len, base); }
201 #else
202  static char* itoa(long src, char *dst, size_t &len, int base = 10) throw () { return itoa((int64_t) src, dst, len, base); }
203  static char* itoa(unsigned long src, char *dst, size_t &len, int base = 10) throw () { return itoa((uint64_t) src, dst, len, base); }
204 #endif
205 
206  static std::string bandwidth(int64_t bps, int decimals = 0) throw ();
207  static std::string bandwidth(uint64_t bps, int decimals = 0) throw ();
208 #ifdef __LP64__
209  static std::string bandwidth(int bps, int decimals = 0) throw () { return bandwidth((int64_t) bps, decimals); }
210  static std::string bandwidth(unsigned int bps, int decimals = 0) throw () { return bandwidth((uint64_t) bps, decimals); }
211  static std::string bandwidth(long long bps, int decimals = 0) throw () { return bandwidth((int64_t) bps, decimals); }
212  static std::string bandwidth(unsigned long long bps, int decimals = 0) throw () { return bandwidth((uint64_t) bps, decimals); }
213 #else
214  static std::string bandwidth(long bps, int decimals = 0) throw () { return bandwidth((int64_t) bps, decimals); }
215  static std::string bandwidth(unsigned long bps, int decimals = 0) throw () { return bandwidth((uint64_t) bps, decimals); }
216 #endif
217 
218  static std::string rate(int64_t bps, int decimals = 0, const std::string &suffix = "s") throw ();
219  static std::string rate(uint64_t bps, int decimals = 0, const std::string &suffix = "s") throw ();
220 #ifdef __LP64__
221  static std::string rate(int bps, int decimals = 0, const std::string &suffix = "s") throw () { return rate((int64_t) bps, decimals, suffix); }
222  static std::string rate(unsigned int bps, int decimals = 0, const std::string &suffix = "s") throw () { return rate((uint64_t) bps, decimals, suffix); }
223  static std::string rate(long long bps, int decimals = 0, const std::string &suffix = "s") throw () { return rate((int64_t) bps, decimals, suffix); }
224  static std::string rate(unsigned long long bps, int decimals = 0, const std::string &suffix = "s") throw () { return rate((uint64_t) bps, decimals, suffix); }
225 #else
226  static std::string rate(long bps, int decimals = 0, const std::string &suffix = "s") throw () { return rate((int64_t) bps, decimals, suffix); }
227  static std::string rate(unsigned long bps, int decimals = 0, const std::string &suffix = "s") throw () { return rate((uint64_t) bps, decimals, suffix); }
228 #endif
229 
230  static std::string dataSize(int64_t bytes, int decimals = 0) throw ();
231  static std::string dataSize(uint64_t bytes, int decimals = 0) throw ();
232 #ifdef __LP64__
233  static std::string dataSize(int bytes, int decimals = 0) throw () { return dataSize((int64_t) bytes, decimals); }
234  static std::string dataSize(unsigned int bytes, int decimals = 0) throw () { return dataSize((uint64_t) bytes, decimals); }
235  static std::string dataSize(long long bytes, int decimals = 0) throw () { return dataSize((int64_t) bytes, decimals); }
236  static std::string dataSize(unsigned long long bytes, int decimals = 0) throw () { return dataSize((uint64_t) bytes, decimals); }
237 #else
238  static std::string dataSize(long bytes, int decimals = 0) throw () { return dataSize((int64_t) bytes, decimals); }
239  static std::string dataSize(unsigned long bytes, int decimals = 0) throw () { return dataSize((uint64_t) bytes, decimals); }
240 #endif
241 
242  static uint64_t dataSize(const std::string &dataSize) throw ();
243 
244  static std::string dataRate(int64_t bps, int decimals = 0) throw ();
245  static std::string dataRate(uint64_t bps, int decimals = 0) throw ();
246 #ifdef __LP64__
247  static std::string dataRate(int bps, int decimals = 0) throw () { return dataRate((uint64_t) bps, decimals); }
248  static std::string dataRate(unsigned int bps, int decimals = 0) throw () { return dataRate((uint64_t) bps, decimals); }
249  static std::string dataRate(long long bps, int decimals = 0) throw () { return dataRate((uint64_t) bps, decimals); }
250  static std::string dataRate(unsigned long long bps, int decimals = 0) throw () { return dataRate((uint64_t) bps, decimals); }
251 #else
252  static std::string dataRate(long bps, int decimals = 0) throw () { return dataRate((int64_t) bps, decimals); }
253  static std::string dataRate(unsigned long bps, int decimals = 0) throw () { return dataRate((uint64_t) bps, decimals); }
254 #endif
255 
256  static uint64_t dataRate(const std::string &dataRate) throw ();
257 
258  static std::string duration(int64_t usec, int decimals = 0) throw ();
259  static std::string duration(uint64_t usec, int decimals = 0) throw ();
260 #ifdef __LP64__
261  static std::string duration(int usec, int decimals = 0) throw () { return duration((int64_t) usec, decimals); }
262  static std::string duration(unsigned int usec, int decimals = 0) throw () { return duration((uint64_t) usec, decimals); }
263  static std::string duration(long long usec, int decimals = 0) throw () { return duration((int64_t) usec, decimals); }
264  static std::string duration(unsigned long long usec, int decimals = 0) throw () { return duration((uint64_t) usec, decimals); }
265 #else
266  static std::string duration(long usec, int decimals = 0) throw () { return duration((int64_t) usec, decimals); }
267  static std::string duration(unsigned long usec, int decimals = 0) throw () { return duration((uint64_t) usec, decimals); }
268 #endif
269 
270  static std::string scale(int64_t value, int decimals = 0) throw (); /* k == thousand, m == million, b == billion, t == trillion, q == quadrillion */
271  static std::string scale(uint64_t value, int decimals = 0) throw ();
272 #ifdef __LP64__
273  static std::string scale(int value, int decimals = 0) throw () { return scale((int64_t) value, decimals); }
274  static std::string scale(unsigned int value, int decimals = 0) throw () { return scale((uint64_t) value, decimals); }
275  static std::string scale(long long value, int decimals = 0) throw () { return scale((int64_t) value, decimals); }
276  static std::string scale(unsigned long long value, int decimals = 0) throw () { return scale((uint64_t) value, decimals); }
277 #else
278  static std::string scale(long value, int decimals = 0) throw () { return scale((int64_t) value, decimals); }
279  static std::string scale(unsigned long value, int decimals = 0) throw () { return scale((uint64_t) value, decimals); }
280 #endif
281 
282  static std::string deflate(const std::string &src, Algo algo = Zlib, int level = DefaultLevel) throw (CompressionException); /* zlib deflate - Do not use c_str on result */
283  static std::vector<char> deflate(const std::vector<char> &src, Algo algo = Zlib, int level = DefaultLevel, size_t size = 0) throw (CompressionException); /* libz deflate */
284  static std::string inflate(const std::string &src, Algo algo = Auto) throw (CompressionException); /* zlib inflate */
285  static std::vector<char> inflate(const std::vector<char> &src, Algo algo = Auto, size_t size = 0) throw (CompressionException); /* zlib inflate */
286 
287  static std::string encrypt(const std::string &src, const std::string &password, const std::string &salt = DefaultSalt(), uint32_t seed = 0) throw (CryptException); /* Do not use c_str on result */
288  static std::string& encrypt(std::string &src, const std::string &password, const std::string &salt = DefaultSalt(), uint32_t seed = 0) throw (CryptException); /* Do not use c_str on result */
289  static std::string decrypt(const std::string &src, const std::string &password, const std::string &salt = DefaultSalt(), uint32_t seed = 0) throw (CryptException);
290  static std::string& decrypt(std::string &src, const std::string &password, const std::string &salt = DefaultSalt(), uint32_t seed = 0) throw (CryptException);
291 
292  static std::string random(size_t len, const std::string &charset = AlphaNumericMixedCase(), uint32_t seed = 0) throw ();
293 
294  static std::string base64_encode(unsigned char const *src, unsigned int in_len, bool standard = true) throw ();
295  static std::string base64_encode(const std::string &src, bool standard = true) throw ();
296  static std::string base64_decode(const std::string &src, bool standard = true) throw ();
297 
298  static bool isPrintable(const std::string &src) throw ();
299 };
300 
301 #endif
302 
303 /*
304 ** vim: noet ts=3 sw=3
305 */