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 lwc_string_unref(corestring_lwc_##NAME); \
45 corestring_lwc_##NAME = NULL; \
46 } while (0)
47
48#define CORESTRING_DOM_VALUE(NAME,VALUE) \
49 do { \
50 if (corestring_dom_##NAME != NULL) { \
51 dom_string_unref(corestring_dom_##NAME); \
52 corestring_dom_##NAME = NULL; \
53 } \
54 } while (0)
55
56#define CORESTRING_NSURL(NAME,VALUE) \
57 do { \
58 if (corestring_nsurl_##NAME != NULL) { \
59 nsurl_unref(corestring_nsurl_##NAME); \
60 corestring_nsurl_##NAME = NULL; \
61 } \
62 } while (0)
63
64
66
67#undef CORESTRING_LWC_VALUE
68#undef CORESTRING_DOM_VALUE
69#undef CORESTRING_NSURL
70
71 return NSERROR_OK;
72}
73
74
75/* exported interface documented in utils/corestrings.h */
77{
78 lwc_error lerror;
79 nserror error;
80 dom_exception exc;
81
82#define CORESTRING_LWC_VALUE(NAME,VALUE) \
83 do { \
84 lerror = lwc_intern_string( \
85 (const char *)VALUE, \
86 sizeof(VALUE) - 1, \
87 &corestring_lwc_##NAME ); \
88 if ((lerror != lwc_error_ok) || \
89 (corestring_lwc_##NAME == NULL)) { \
90 error = NSERROR_NOMEM; \
91 goto error; \
92 } \
93 } while(0)
94
95#define CORESTRING_DOM_VALUE(NAME,VALUE) \
96 do { \
97 exc = dom_string_create_interned( \
98 (const uint8_t *)VALUE, \
99 sizeof(VALUE) - 1, \
100 &corestring_dom_##NAME ); \
101 if ((exc != DOM_NO_ERR) || \
102 (corestring_dom_##NAME == NULL)) { \
103 error = NSERROR_NOMEM; \
104 goto error; \
105 } \
106 } while(0)
107
108#define CORESTRING_NSURL(NAME,VALUE) \
109 do { \
110 error = nsurl_create(VALUE, \
111 &corestring_nsurl_##NAME); \
112 if (error != NSERROR_OK) { \
113 goto error; \
114 } \
115 } while(0)
116
117#include "utils/corestringlist.h"
118
119#undef CORESTRING_LWC_VALUE
120#undef CORESTRING_DOM_VALUE
121#undef CORESTRING_NSURL
122
123 return NSERROR_OK;
124
125error:
127
128 return error;
129}
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:76
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.