NetSurf
corestrings.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Michael Drake <tlsa@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Useful interned string tables implementation.
22 */
23
24#include <dom/dom.h>
25
26#include "utils/corestrings.h"
27#include "utils/nsurl.h"
28#include "utils/utils.h"
29
30/* define corestrings */
31#define CORESTRING_LWC_VALUE(NAME,VALUE) lwc_string *corestring_lwc_##NAME
32#define CORESTRING_DOM_VALUE(NAME,VALUE) dom_string *corestring_dom_##NAME
33#define CORESTRING_NSURL(NAME,VALUE) nsurl *corestring_nsurl_##NAME
35#undef CORESTRING_LWC_VALUE
36#undef CORESTRING_DOM_VALUE
37#undef CORESTRING_NSURL
38
39/* exported interface documented in utils/corestrings.h */
41{
42#define CORESTRING_LWC_VALUE(NAME,VALUE) \
43 do { \
44 if (corestring_lwc_##NAME != NULL) { \
45 lwc_string_unref(corestring_lwc_##NAME); \
46 corestring_lwc_##NAME = NULL; \
47 } \
48 } while (0)
49
50#define CORESTRING_DOM_VALUE(NAME,VALUE) \
51 do { \
52 if (corestring_dom_##NAME != NULL) { \
53 dom_string_unref(corestring_dom_##NAME); \
54 corestring_dom_##NAME = NULL; \
55 } \
56 } while (0)
57
58#define CORESTRING_NSURL(NAME,VALUE) \
59 do { \
60 if (corestring_nsurl_##NAME != NULL) { \
61 nsurl_unref(corestring_nsurl_##NAME); \
62 corestring_nsurl_##NAME = NULL; \
63 } \
64 } while (0)
65
66
68
69#undef CORESTRING_LWC_VALUE
70#undef CORESTRING_DOM_VALUE
71#undef CORESTRING_NSURL
72
73 return NSERROR_OK;
74}
75
76
77/* exported interface documented in utils/corestrings.h */
79{
80 lwc_error lerror;
81 nserror error;
82 dom_exception exc;
83
84#define CORESTRING_LWC_VALUE(NAME,VALUE) \
85 do { \
86 lerror = lwc_intern_string( \
87 (const char *)VALUE, \
88 sizeof(VALUE) - 1, \
89 &corestring_lwc_##NAME ); \
90 if ((lerror != lwc_error_ok) || \
91 (corestring_lwc_##NAME == NULL)) { \
92 error = NSERROR_NOMEM; \
93 goto error; \
94 } \
95 } while(0)
96
97#define CORESTRING_DOM_VALUE(NAME,VALUE) \
98 do { \
99 exc = dom_string_create_interned( \
100 (const uint8_t *)VALUE, \
101 sizeof(VALUE) - 1, \
102 &corestring_dom_##NAME ); \
103 if ((exc != DOM_NO_ERR) || \
104 (corestring_dom_##NAME == NULL)) { \
105 error = NSERROR_NOMEM; \
106 goto error; \
107 } \
108 } while(0)
109
110#define CORESTRING_NSURL(NAME,VALUE) \
111 do { \
112 error = nsurl_create(VALUE, \
113 &corestring_nsurl_##NAME); \
114 if (error != NSERROR_OK) { \
115 goto error; \
116 } \
117 } while(0)
118
119#include "utils/corestringlist.h"
120
121#undef CORESTRING_LWC_VALUE
122#undef CORESTRING_DOM_VALUE
123#undef CORESTRING_NSURL
124
125 return NSERROR_OK;
126
127error:
129
130 return error;
131}
Core string lists.
nserror corestrings_fini(void)
free resources of core string tables.
Definition: corestrings.c:40
nserror corestrings_init(void)
Initialise the core string tables.
Definition: corestrings.c:78
Useful interned string pointers (interface).
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
NetSurf URL handling (interface).
Interface to a number of general purpose functionality.