aboutsummaryrefslogtreecommitdiff
path: root/src/lib/mhd_str.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mhd_str.h')
-rw-r--r--src/lib/mhd_str.h103
1 files changed, 56 insertions, 47 deletions
diff --git a/src/lib/mhd_str.h b/src/lib/mhd_str.h
index 410cc36e..f0f6511d 100644
--- a/src/lib/mhd_str.h
+++ b/src/lib/mhd_str.h
@@ -42,7 +42,7 @@
42/** 42/**
43 * Determine length of static string / macro strings at compile time. 43 * Determine length of static string / macro strings at compile time.
44 */ 44 */
45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1) 45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
46#endif /* ! MHD_STATICSTR_LEN_ */ 46#endif /* ! MHD_STATICSTR_LEN_ */
47 47
48/* 48/*
@@ -58,11 +58,12 @@
58 * @return non-zero if two strings are equal, zero otherwise. 58 * @return non-zero if two strings are equal, zero otherwise.
59 */ 59 */
60int 60int
61MHD_str_equal_caseless_ (const char * str1, 61MHD_str_equal_caseless_ (const char *str1,
62 const char * str2); 62 const char *str2);
63#else /* MHD_FAVOR_SMALL_CODE */ 63#else /* MHD_FAVOR_SMALL_CODE */
64/* Reuse MHD_str_equal_caseless_n_() to reduce size */ 64/* Reuse MHD_str_equal_caseless_n_() to reduce size */
65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_((s1),(s2), SIZE_MAX) 65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
66 SIZE_MAX)
66#endif /* MHD_FAVOR_SMALL_CODE */ 67#endif /* MHD_FAVOR_SMALL_CODE */
67 68
68 69
@@ -77,9 +78,9 @@ MHD_str_equal_caseless_ (const char * str1,
77 * @return non-zero if two strings are equal, zero otherwise. 78 * @return non-zero if two strings are equal, zero otherwise.
78 */ 79 */
79int 80int
80MHD_str_equal_caseless_n_ (const char * const str1, 81MHD_str_equal_caseless_n_ (const char *const str1,
81 const char * const str2, 82 const char *const str2,
82 size_t maxlen); 83 size_t maxlen);
83 84
84 85
85/** 86/**
@@ -96,8 +97,8 @@ MHD_str_equal_caseless_n_ (const char * const str1,
96 * @return non-zero if two strings are equal, zero otherwise. 97 * @return non-zero if two strings are equal, zero otherwise.
97 */ 98 */
98bool 99bool
99MHD_str_has_token_caseless_ (const char * str, 100MHD_str_has_token_caseless_ (const char *str,
100 const char * const token, 101 const char *const token,
101 size_t token_len); 102 size_t token_len);
102 103
103/** 104/**
@@ -111,7 +112,7 @@ MHD_str_has_token_caseless_ (const char * str,
111 * @return non-zero if two strings are equal, zero otherwise. 112 * @return non-zero if two strings are equal, zero otherwise.
112 */ 113 */
113#define MHD_str_has_s_token_caseless_(str,tkn) \ 114#define MHD_str_has_s_token_caseless_(str,tkn) \
114 MHD_str_has_token_caseless_((str),(tkn),MHD_STATICSTR_LEN_(tkn)) 115 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
115 116
116#ifndef MHD_FAVOR_SMALL_CODE 117#ifndef MHD_FAVOR_SMALL_CODE
117/* Use individual function for each case to improve speed */ 118/* Use individual function for each case to improve speed */
@@ -126,13 +127,13 @@ MHD_str_has_token_caseless_ (const char * str,
126 * then possible to store in uint64_t or @a out_val is NULL 127 * then possible to store in uint64_t or @a out_val is NULL
127 */ 128 */
128size_t 129size_t
129MHD_str_to_uint64_ (const char * str, 130MHD_str_to_uint64_ (const char *str,
130 uint64_t * out_val); 131 uint64_t *out_val);
131 132
132/** 133/**
133 * Convert not more then @a maxlen decimal US-ASCII digits in string to 134 * Convert not more then @a maxlen decimal US-ASCII digits in string to
134 * number in uint64_t. 135 * number in uint64_t.
135 * Conversion stopped at first non-digit character or after @a maxlen 136 * Conversion stopped at first non-digit character or after @a maxlen
136 * digits. 137 * digits.
137 * @param str string to convert 138 * @param str string to convert
138 * @param maxlen maximum number of characters to process 139 * @param maxlen maximum number of characters to process
@@ -142,9 +143,9 @@ MHD_str_to_uint64_ (const char * str,
142 * then possible to store in uint64_t or @a out_val is NULL 143 * then possible to store in uint64_t or @a out_val is NULL
143 */ 144 */
144size_t 145size_t
145MHD_str_to_uint64_n_ (const char * str, 146MHD_str_to_uint64_n_ (const char *str,
146 size_t maxlen, 147 size_t maxlen,
147 uint64_t * out_val); 148 uint64_t *out_val);
148 149
149 150
150/** 151/**
@@ -152,19 +153,19 @@ MHD_str_to_uint64_n_ (const char * str,
152 * Conversion stopped at first non-digit character. 153 * Conversion stopped at first non-digit character.
153 * @param str string to convert 154 * @param str string to convert
154 * @param out_val pointer to uint32_t to store result of conversion 155 * @param out_val pointer to uint32_t to store result of conversion
155 * @return non-zero number of characters processed on succeed, 156 * @return non-zero number of characters processed on succeed,
156 * zero if no digit is found, resulting value is larger 157 * zero if no digit is found, resulting value is larger
157 * then possible to store in uint32_t or @a out_val is NULL 158 * then possible to store in uint32_t or @a out_val is NULL
158 */ 159 */
159size_t 160size_t
160MHD_strx_to_uint32_ (const char * str, 161MHD_strx_to_uint32_ (const char *str,
161 uint32_t * out_val); 162 uint32_t *out_val);
162 163
163 164
164/** 165/**
165 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 166 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
166 * to number in uint32_t. 167 * to number in uint32_t.
167 * Conversion stopped at first non-digit character or after @a maxlen 168 * Conversion stopped at first non-digit character or after @a maxlen
168 * digits. 169 * digits.
169 * @param str string to convert 170 * @param str string to convert
170 * @param maxlen maximum number of characters to process 171 * @param maxlen maximum number of characters to process
@@ -174,9 +175,9 @@ MHD_strx_to_uint32_ (const char * str,
174 * then possible to store in uint32_t or @a out_val is NULL 175 * then possible to store in uint32_t or @a out_val is NULL
175 */ 176 */
176size_t 177size_t
177MHD_strx_to_uint32_n_ (const char * str, 178MHD_strx_to_uint32_n_ (const char *str,
178 size_t maxlen, 179 size_t maxlen,
179 uint32_t * out_val); 180 uint32_t *out_val);
180 181
181 182
182/** 183/**
@@ -184,19 +185,19 @@ MHD_strx_to_uint32_n_ (const char * str,
184 * Conversion stopped at first non-digit character. 185 * Conversion stopped at first non-digit character.
185 * @param str string to convert 186 * @param str string to convert
186 * @param out_val pointer to uint64_t to store result of conversion 187 * @param out_val pointer to uint64_t to store result of conversion
187 * @return non-zero number of characters processed on succeed, 188 * @return non-zero number of characters processed on succeed,
188 * zero if no digit is found, resulting value is larger 189 * zero if no digit is found, resulting value is larger
189 * then possible to store in uint64_t or @a out_val is NULL 190 * then possible to store in uint64_t or @a out_val is NULL
190 */ 191 */
191size_t 192size_t
192MHD_strx_to_uint64_ (const char * str, 193MHD_strx_to_uint64_ (const char *str,
193 uint64_t * out_val); 194 uint64_t *out_val);
194 195
195 196
196/** 197/**
197 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 198 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
198 * to number in uint64_t. 199 * to number in uint64_t.
199 * Conversion stopped at first non-digit character or after @a maxlen 200 * Conversion stopped at first non-digit character or after @a maxlen
200 * digits. 201 * digits.
201 * @param str string to convert 202 * @param str string to convert
202 * @param maxlen maximum number of characters to process 203 * @param maxlen maximum number of characters to process
@@ -206,9 +207,9 @@ MHD_strx_to_uint64_ (const char * str,
206 * then possible to store in uint64_t or @a out_val is NULL 207 * then possible to store in uint64_t or @a out_val is NULL
207 */ 208 */
208size_t 209size_t
209MHD_strx_to_uint64_n_ (const char * str, 210MHD_strx_to_uint64_n_ (const char *str,
210 size_t maxlen, 211 size_t maxlen,
211 uint64_t * out_val); 212 uint64_t *out_val);
212 213
213#else /* MHD_FAVOR_SMALL_CODE */ 214#else /* MHD_FAVOR_SMALL_CODE */
214/* Use one universal function and macros to reduce size */ 215/* Use one universal function and macros to reduce size */
@@ -216,7 +217,7 @@ MHD_strx_to_uint64_n_ (const char * str,
216/** 217/**
217 * Generic function for converting not more then @a maxlen 218 * Generic function for converting not more then @a maxlen
218 * hexadecimal or decimal US-ASCII digits in string to number. 219 * hexadecimal or decimal US-ASCII digits in string to number.
219 * Conversion stopped at first non-digit character or after @a maxlen 220 * Conversion stopped at first non-digit character or after @a maxlen
220 * digits. 221 * digits.
221 * To be used only within macro. 222 * To be used only within macro.
222 * @param str the string to convert 223 * @param str the string to convert
@@ -230,36 +231,44 @@ MHD_strx_to_uint64_n_ (const char * str,
230 * then @ max_val or @a out_val is NULL 231 * then @ max_val or @a out_val is NULL
231 */ 232 */
232size_t 233size_t
233MHD_str_to_uvalue_n_ (const char * str, 234MHD_str_to_uvalue_n_ (const char *str,
234 size_t maxlen, 235 size_t maxlen,
235 void * out_val, 236 void *out_val,
236 size_t val_size, 237 size_t val_size,
237 uint64_t max_val, 238 uint64_t max_val,
238 int base); 239 int base);
239 240
240#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 241#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
241 sizeof(uint64_t),UINT64_MAX,10) 242 sizeof(uint64_t), \
243 UINT64_MAX,10)
242 244
243#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 245#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
244 sizeof(uint64_t),UINT64_MAX,10) 246 sizeof(uint64_t), \
247 UINT64_MAX,10)
245 248
246#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 249#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
247 sizeof(size_t),SIZE_MAX,16) 250 sizeof(size_t),SIZE_MAX, \
251 16)
248 252
249#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 253#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
250 sizeof(size_t),SIZE_MAX,16) 254 sizeof(size_t), \
255 SIZE_MAX,16)
251 256
252#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 257#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
253 sizeof(uint32_t),UINT32_MAX,16) 258 sizeof(uint32_t), \
259 UINT32_MAX,16)
254 260
255#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 261#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
256 sizeof(uint32_t),UINT32_MAX,16) 262 sizeof(uint32_t), \
263 UINT32_MAX,16)
257 264
258#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 265#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
259 sizeof(uint64_t),UINT64_MAX,16) 266 sizeof(uint64_t), \
267 UINT64_MAX,16)
260 268
261#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 269#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
262 sizeof(uint64_t),UINT64_MAX,16) 270 sizeof(uint64_t), \
271 UINT64_MAX,16)
263 272
264#endif /* MHD_FAVOR_SMALL_CODE */ 273#endif /* MHD_FAVOR_SMALL_CODE */
265 274