Debian Codegraph @

src/common/public/oscap_text.h

raw symbols SCIP
1 /*
2 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "David Niemoller" <[email protected]>
21 * Lukas Kuklinek <[email protected]>
22 */
23
24 /**
25 * @file
26 * Multilingual text processing interface.
27 * @author Lukas Kuklinek <[email protected]>
28 * @author David Niemoller <[email protected]>
29 *
30 * @addtogroup COMMON
31 * @{
32 * @addtogroup STRINGS
33 * @{
34 * Functions to access and manipulate textual data.
35 */
36
37 #pragma once
38 #ifndef OSCAP_TEXT_H_
39 #define OSCAP_TEXT_H_
40
41 #include <stdbool.h>
42 #include "oscap_export.h"
43
44 /**
45 * @name Common language codes
46 * @{
47 */
48 /// English
49 OSCAP_API extern const char *const OSCAP_LANG_ENGLISH;
50 /// American English
51 OSCAP_API extern const char *const OSCAP_LANG_ENGLISH_US;
52 /// Default language (i.e. American English)
53 OSCAP_API extern const char *const OSCAP_LANG_DEFAULT;
54 /** @} */
55
56 /**
57 * @struct oscap_text
58 * Representation of internationalizable character strings
59 */
60 struct oscap_text;
61
62 /**
63 * @struct oscap_stringlist
64 * A collection of strings.
65 */
66 struct oscap_stringlist;
67
68 /**
69 * Create an internationalized text field.
70 * @param lang - language identifier (@see oscap_text_lang)
71 * @param encoding - language encoding (@see oscap_text_encoding)
72 * @memberof oscap_text
73 */
74 OSCAP_API struct oscap_text *oscap_text_new(void);
75
76 /**
77 * Clone an internationalized text field.
78 * @param text oscap_text structure to clone
79 * @memberof oscap_text
80 */
81 OSCAP_API struct oscap_text *oscap_text_clone(const struct oscap_text * text);
82
83 /**
84 * Create an internationalized text field with HTML content.
85 * @param lang - language identifier (@see oscap_text_lang)
86 * @param encoding - language encoding (@see oscap_text_encoding)
87 * @memberof oscap_text
88 */
89 OSCAP_API struct oscap_text *oscap_text_new_html(void);
90
91 /**
92 * Release an internationalized text field.
93 * @memberof oscap_text
94 */
95 OSCAP_API void oscap_text_free(struct oscap_text *);
96
97 /************************************************************/
98 /**
99 * @name Getters
100 * Return value is pointer to structure's member. Do not free unless you null the pointer in the structure.
101 * Use remove function otherwise.
102 * @{
103 * */
104
105 /// @memberof oscap_stringlist
106 OSCAP_API struct oscap_string_iterator *oscap_stringlist_get_strings(const struct oscap_stringlist* list);
107 /// @memberof oscap_stringlist
108 OSCAP_API struct oscap_stringlist *oscap_stringlist_clone(struct oscap_stringlist *list);
109
110 /// @memberof oscap_text
111 OSCAP_API const char *oscap_text_get_text(const struct oscap_text *text);
112 /// @memberof oscap_text
113 OSCAP_API const char *oscap_text_get_lang(const struct oscap_text *text);
114 /**
115 * Get plaintext representation of the text.
116 * Caller is responsible for freeing returned string.
117 * @memberof oscap_text
118 */
119 OSCAP_API char *oscap_text_get_plaintext(const struct oscap_text *text);
120
121 /**
122 * Does this text posses a HTML content?
123 * @memberof oscap_text
124 */
125 OSCAP_API bool oscap_text_get_is_html(const struct oscap_text *text);
126 /**
127 * Can this text contain substitutions?
128 * @memberof oscap_text
129 */
130 OSCAP_API bool oscap_text_get_can_substitute(const struct oscap_text *text);
131 /**
132 * Can this text override parent content?
133 * @memberof oscap_text
134 */
135 OSCAP_API bool oscap_text_get_can_override(const struct oscap_text *text);
136 /**
137 * Does this text override parent content?
138 * @memberof oscap_text
139 */
140 OSCAP_API bool oscap_text_get_overrides(const struct oscap_text *text);
141
142 /************************************************************/
143 /** @} End of Getters group */
144
145 /************************************************************/
146 /**
147 * @name Setters
148 * For lists use add functions. Parameters of set functions are duplicated in memory and need to
149 * be freed by caller.
150 * @{
151 */
152
153 /**
154 * Set whether this text overrides parent content.
155 * @memberof oscap_text
156 */
157 OSCAP_API bool oscap_text_set_overrides(struct oscap_text *text, bool overrides);
158
159 /// @memberof oscap_text
160 OSCAP_API bool oscap_text_set_text(struct oscap_text *text, const char * string);
161 /// @memberof oscap_text
162 OSCAP_API bool oscap_text_set_lang(struct oscap_text *text, const char *string);
163
164 /// @memberof oscap_stringlist
165 OSCAP_API bool oscap_stringlist_add_string(struct oscap_stringlist* list, const char *str);
166 /// @memberof oscap_stringlist
167 OSCAP_API struct oscap_stringlist * oscap_stringlist_new(void);
168 /// @memberof oscap_stringlist
169 OSCAP_API void oscap_stringlist_free(struct oscap_stringlist *list);
170
171
172 /************************************************************/
173 /** @} End of Setters group */
174
175 /************************************************************/
176 /**
177 * @name Iterators
178 * @{
179 * */
180
181 /** @struct oscap_text_iterator
182 * Internationalized string iterator.
183 * @see oscap_iterator
184 */
185 struct oscap_text_iterator;
186 /// @memberof oscap_text_iterator
187 OSCAP_API struct oscap_text *oscap_text_iterator_next(struct oscap_text_iterator *it);
188 /// @memberof oscap_text_iterator
189 OSCAP_API bool oscap_text_iterator_has_more(struct oscap_text_iterator *it);
190 /// @memberof oscap_text_iterator
191 OSCAP_API void oscap_text_iterator_free(struct oscap_text_iterator *it);
192 /// @memberof oscap_text_iterator
193 OSCAP_API void oscap_text_iterator_remove(struct oscap_text_iterator *it);
194 /// @memberof oscap_text_iterator
195 OSCAP_API void oscap_text_iterator_reset(struct oscap_text_iterator *it);
196
197 /**
198 * @struct oscap_string_iterator
199 * String iterator.
200 *
201 * An iterator iterating over a collection of char*-s.
202 * @see oscap_iterator
203 */
204 struct oscap_string_iterator;
205 /// @memberof oscap_string_iterator
206 OSCAP_API const char *oscap_string_iterator_next(struct oscap_string_iterator *it);
207 /// @memberof oscap_string_iterator
208 OSCAP_API bool oscap_string_iterator_has_more(struct oscap_string_iterator *it);
209 /// @memberof oscap_string_iterator
210 OSCAP_API void oscap_string_iterator_free(struct oscap_string_iterator *it);
211 /// @memberof oscap_string_iterator
212 OSCAP_API void oscap_string_iterator_remove(struct oscap_string_iterator *it);
213 /// @memberof oscap_string_iterator
214 OSCAP_API void oscap_string_iterator_reset(struct oscap_string_iterator *it);
215
216 /**
217 * @struct oscap_stringlist_iterator
218 * Iterator over collections of strings.
219 * @see oscap_iterator
220 */
221 struct oscap_stringlist_iterator;
222 /// @memberof oscap_stringlist_iterator
223 OSCAP_API struct oscap_stringlist *oscap_stringlist_iterator_next(struct oscap_stringlist_iterator *it);
224 /// @memberof oscap_stringlist_iterator
225 OSCAP_API bool oscap_stringlist_iterator_has_more(struct oscap_stringlist_iterator *it);
226 /// @memberof oscap_stringlist_iterator
227 OSCAP_API void oscap_stringlist_iterator_free(struct oscap_stringlist_iterator *it);
228 /// @memberof oscap_stringlist_iterator
229 OSCAP_API void oscap_stringlist_iterator_remove(struct oscap_stringlist_iterator *it);
230 /// @memberof oscap_stringlist_iterator
231 OSCAP_API void oscap_stringlist_iterator_reset(struct oscap_stringlist_iterator *it);
232
233 /************************************************************/
234 /** @} End of Iterators group */
235
236 /** @} */
237
238 /**
239 * @brief gets a plaintext string representing given textlist
240 *
241 * Iterates through given texts and looks at each to see if the language matches
242 * given preferred_lang. If preferred_lang is NULL, OSCAP_DEFAULT_LANG is matched.
243 *
244 * If a match is found it, a copy of plaintext representation of that text is
245 * returned. If nothing is found, plaintext representation of the first text in
246 * the list is returned. If the textlist is empty, NULL is returned.
247 */
248 OSCAP_API char* oscap_textlist_get_preferred_plaintext(struct oscap_text_iterator* texts, const char* preferred_lang);
249
250 /**
251 * @brief gets oscap_text representing given textlist
252 *
253 * Similar to @ref oscap_textlist_get_preferred_plaintext but returns oscap_text
254 * instead of just the plaintext.
255 */
256 OSCAP_API struct oscap_text *oscap_textlist_get_preferred_text(struct oscap_text_iterator *texts, const char *preferred_lang);
257
258
259 /** @} */
260
261 #endif
262