-rw-r--r-- | include/opkele/util.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/include/opkele/util.h b/include/opkele/util.h index fd974a1..0130bff 100644 --- a/include/opkele/util.h +++ b/include/opkele/util.h | |||
@@ -1,89 +1,97 @@ | |||
1 | #ifndef __OPKELE_UTIL_H | 1 | #ifndef __OPKELE_UTIL_H |
2 | #define __OPKELE_UTIL_H | 2 | #define __OPKELE_UTIL_H |
3 | 3 | ||
4 | #include <time.h> | 4 | #include <time.h> |
5 | #include <string> | 5 | #include <string> |
6 | #include <vector> | 6 | #include <vector> |
7 | #include <opkele/types.h> | 7 | #include <opkele/types.h> |
8 | 8 | ||
9 | namespace opkele { | 9 | namespace opkele { |
10 | using std::string; | 10 | using std::string; |
11 | using std::vector; | 11 | using std::vector; |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * @brief opkele utils namespace | 14 | * @brief opkele utils namespace |
15 | */ | 15 | */ |
16 | namespace util { | 16 | namespace util { |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Convert internal time representation to w3c format | 19 | * Convert internal time representation to w3c format |
20 | * @param t internal representation | 20 | * @param t internal representation |
21 | * @return w3c time | 21 | * @return w3c time |
22 | * @throw failed_conversion in case of error | 22 | * @throw failed_conversion in case of error |
23 | */ | 23 | */ |
24 | string time_to_w3c(time_t t); | 24 | string time_to_w3c(time_t t); |
25 | /** | 25 | /** |
26 | * Convert W3C time representation to internal time_t | 26 | * Convert W3C time representation to internal time_t |
27 | * @param w w3c representation | 27 | * @param w w3c representation |
28 | * @return converted time | 28 | * @return converted time |
29 | * @throw failed_conversion in case of error | 29 | * @throw failed_conversion in case of error |
30 | */ | 30 | */ |
31 | time_t w3c_to_time(const string& w); | 31 | time_t w3c_to_time(const string& w); |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Encode string to the representation suitable for using in URL. | 34 | * Encode string to the representation suitable for using in URL |
35 | * @param str string to encode | 35 | * @param str string to encode |
36 | * @return encoded string | 36 | * @return encoded string |
37 | * @throw failed_conversion in case of failure | 37 | * @throw failed_conversion in case of failure |
38 | */ | 38 | */ |
39 | string url_encode(const string& str); | 39 | string url_encode(const string& str); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Decode url-encoded string back to normal | ||
43 | * @param str url-encoded string | ||
44 | * @return decoded string | ||
45 | * @throw failed_conversion in case of failure | ||
46 | */ | ||
47 | string url_decode(const string& str); | ||
48 | |||
49 | /** | ||
42 | * Make string suitable for using as x(ht)ml attribute. | 50 | * Make string suitable for using as x(ht)ml attribute. |
43 | * @param str string to escape | 51 | * @param str string to escape |
44 | * @return escaped string | 52 | * @return escaped string |
45 | */ | 53 | */ |
46 | string attr_escape(const string& str); | 54 | string attr_escape(const string& str); |
47 | 55 | ||
48 | /** | 56 | /** |
49 | * Convert number to string | 57 | * Convert number to string |
50 | * @param l number | 58 | * @param l number |
51 | * @return string representation | 59 | * @return string representation |
52 | * @throw failed_conversion in case of failure | 60 | * @throw failed_conversion in case of failure |
53 | */ | 61 | */ |
54 | string long_to_string(long l); | 62 | string long_to_string(long l); |
55 | /** | 63 | /** |
56 | * Convert string to number | 64 | * Convert string to number |
57 | * @param s string, containing the number | 65 | * @param s string, containing the number |
58 | * @return the number | 66 | * @return the number |
59 | * @throw failed_conversion in case of failure | 67 | * @throw failed_conversion in case of failure |
60 | */ | 68 | */ |
61 | long string_to_long(const string& s); | 69 | long string_to_long(const string& s); |
62 | 70 | ||
63 | /** | 71 | /** |
64 | * Encode binary data using base64. | 72 | * Encode binary data using base64. |
65 | * @param data pointer to binary data | 73 | * @param data pointer to binary data |
66 | * @param length length of data | 74 | * @param length length of data |
67 | * @return encoded data | 75 | * @return encoded data |
68 | */ | 76 | */ |
69 | string encode_base64(const void *data,size_t length); | 77 | string encode_base64(const void *data,size_t length); |
70 | /** | 78 | /** |
71 | * Decode binary data from base64 representation. | 79 | * Decode binary data from base64 representation. |
72 | * @param data base64-encoded data | 80 | * @param data base64-encoded data |
73 | * @param rv container for decoded binary | 81 | * @param rv container for decoded binary |
74 | */ | 82 | */ |
75 | void decode_base64(const string& data,vector<unsigned char>& rv); | 83 | void decode_base64(const string& data,vector<unsigned char>& rv); |
76 | 84 | ||
77 | /** | 85 | /** |
78 | * Normalize http(s) URI according to RFC3986, section 6. URI is | 86 | * Normalize http(s) URI according to RFC3986, section 6. URI is |
79 | * expected to have scheme: in front of it. | 87 | * expected to have scheme: in front of it. |
80 | * @param uri URI | 88 | * @param uri URI |
81 | * @return normalized URI | 89 | * @return normalized URI |
82 | * @throw not_implemented in case of non-httpi(s) URI | 90 | * @throw not_implemented in case of non-httpi(s) URI |
83 | * @throw bad_input in case of malformed URI | 91 | * @throw bad_input in case of malformed URI |
84 | */ | 92 | */ |
85 | string rfc_3986_normalize_uri(const string& uri); | 93 | string rfc_3986_normalize_uri(const string& uri); |
86 | 94 | ||
87 | string normalize_identifier(const string& usi,bool strip_fragment); | 95 | string normalize_identifier(const string& usi,bool strip_fragment); |
88 | 96 | ||
89 | /** | 97 | /** |