XenevaOS
Loading...
Searching...
No Matches
libwapcaplet.h
Go to the documentation of this file.
1/* libwapcaplet.h
2 *
3 * String internment and management tools.
4 *
5 * Copyright 2009 The NetSurf Browser Project.
6 * Daniel Silverstone <dsilvers@netsurf-browser.org>
7 */
8
9#ifndef libwapcaplet_h_
10#define libwapcaplet_h_
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17#include <sys/types.h>
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21#include <assert.h>
22
27
32
49
56typedef void (*lwc_iteration_callback_fn)(lwc_string *str, void *pw);
57
66
90extern lwc_error lwc_intern_string(const char *s, size_t slen,
91 lwc_string **ret);
92
106 size_t ssoffset, size_t sslen,
107 lwc_string **ret);
108
118
136#if defined(STMTEXPR)
137#define lwc_string_ref(str) ({lwc_string *__lwc_s = (str); assert(__lwc_s != NULL); __lwc_s->refcnt++; __lwc_s;})
138#else
139static inline lwc_string *
140lwc_string_ref(lwc_string *str)
141{
142 assert(str != NULL);
143 str->refcnt++;
144 return str;
145}
146#endif
147
159#define lwc_string_unref(str) { \
160 lwc_string *__lwc_s = (str); \
161 assert(__lwc_s != NULL); \
162 __lwc_s->refcnt--; \
163 if ((__lwc_s->refcnt == 0) || \
164 ((__lwc_s->refcnt == 1) && (__lwc_s->insensitive == __lwc_s))) \
165 lwc_string_destroy(__lwc_s); \
166 }
167
175extern void lwc_string_destroy(lwc_string *str);
176
186#define lwc_string_isequal(str1, str2, ret) \
187 ((*(ret) = ((str1) == (str2))), lwc_error_ok)
188
200extern lwc_error
202
203#if defined(STMTEXPR)
213#define lwc_string_caseless_isequal(_str1,_str2,_ret) ({ \
214 lwc_error __lwc_err = lwc_error_ok; \
215 lwc_string *__lwc_str1 = (_str1); \
216 lwc_string *__lwc_str2 = (_str2); \
217 bool *__lwc_ret = (_ret); \
218 \
219 if (__lwc_str1->insensitive == NULL) { \
220 __lwc_err = lwc__intern_caseless_string(__lwc_str1); \
221 } \
222 if (__lwc_err == lwc_error_ok && __lwc_str2->insensitive == NULL) { \
223 __lwc_err = lwc__intern_caseless_string(__lwc_str2); \
224 } \
225 if (__lwc_err == lwc_error_ok) \
226 *__lwc_ret = (__lwc_str1->insensitive == __lwc_str2->insensitive); \
227 __lwc_err; \
228 })
229
230#else
240static inline lwc_error
241lwc_string_caseless_isequal(lwc_string *str1, lwc_string *str2, bool *ret)
242{
244 if (str1->insensitive == NULL) {
245 err = lwc__intern_caseless_string(str1);
246 }
247 if (err == lwc_error_ok && str2->insensitive == NULL) {
248 err = lwc__intern_caseless_string(str2);
249 }
250 if (err == lwc_error_ok)
251 *ret = (str1->insensitive == str2->insensitive);
252 return err;
253}
254#endif
255
256#if defined(STMTEXPR)
257#define lwc__assert_and_expr(str, expr) ({assert(str != NULL); expr;})
258#else
259#define lwc__assert_and_expr(str, expr) (expr)
260#endif
261
274#define lwc_string_data(str) lwc__assert_and_expr(str, (const char *)((str)+1))
275
282#define lwc_string_length(str) lwc__assert_and_expr(str, (str)->len)
283
296#define lwc_string_hash_value(str) lwc__assert_and_expr(str, (str)->hash)
297
306static inline lwc_error lwc_string_caseless_hash_value(
307 lwc_string *str, lwc_hash *hash)
308{
309 if (str->insensitive == NULL) {
311 if (err != lwc_error_ok) {
312 return err;
313 }
314 }
315
316 *hash = str->insensitive->hash;
317 return lwc_error_ok;
318}
319
320
331extern void lwc_iterate_strings(lwc_iteration_callback_fn cb, void *pw);
332
333#ifdef __cplusplus
334}
335#endif
336
337#endif /* libwapcaplet_h_ */
#define assert(expr)
Definition assert.h:32
unsigned int uint32_t
Definition acefiex.h:163
#define NULL
Definition actypes.h:561
lwc_error lwc_string_tolower(lwc_string *str, lwc_string **ret)
Definition libwapcaplet.c:168
lwc_error lwc_intern_substring(lwc_string *str, size_t ssoffset, size_t sslen, lwc_string **ret)
Definition libwapcaplet.c:152
lwc_error lwc_intern_string(const char *s, size_t slen, lwc_string **ret)
Definition libwapcaplet.c:143
uint32_t lwc_hash
Definition libwapcaplet.h:31
struct lwc_string_s lwc_string
enum lwc_error_e lwc_error
void(* lwc_iteration_callback_fn)(lwc_string *str, void *pw)
Definition libwapcaplet.h:56
void lwc_string_destroy(lwc_string *str)
Definition libwapcaplet.c:187
void lwc_iterate_strings(lwc_iteration_callback_fn cb, void *pw)
Definition libwapcaplet.c:270
lwc_error_e
Definition libwapcaplet.h:61
@ lwc_error_ok
Definition libwapcaplet.h:62
@ lwc_error_oom
Definition libwapcaplet.h:63
@ lwc_error_range
Definition libwapcaplet.h:64
uint32_t lwc_refcounter
Definition libwapcaplet.h:26
lwc_error lwc__intern_caseless_string(lwc_string *str)
Definition libwapcaplet.c:255
Definition libwapcaplet.h:41
struct lwc_string_s * next
Definition libwapcaplet.h:43
size_t len
Definition libwapcaplet.h:44
lwc_refcounter refcnt
Definition libwapcaplet.h:46
struct lwc_string_s * insensitive
Definition libwapcaplet.h:47
lwc_hash hash
Definition libwapcaplet.h:45
struct lwc_string_s ** prevptr
Definition libwapcaplet.h:42