|
|
|||
File indexing completed on 2026-05-06 08:41:18
0001 /* gmarkup.h - Simple XML-like string parser/writer 0002 * 0003 * Copyright 2000 Red Hat, Inc. 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-or-later 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Lesser General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2.1 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public License 0018 * along with this library; if not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #ifndef __G_MARKUP_H__ 0022 #define __G_MARKUP_H__ 0023 0024 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) 0025 #error "Only <glib.h> can be included directly." 0026 #endif 0027 0028 #include <stdarg.h> 0029 0030 #include <glib/gerror.h> 0031 #include <glib/gslist.h> 0032 0033 G_BEGIN_DECLS 0034 0035 /** 0036 * GMarkupError: 0037 * @G_MARKUP_ERROR_BAD_UTF8: text being parsed was not valid UTF-8 0038 * @G_MARKUP_ERROR_EMPTY: document contained nothing, or only whitespace 0039 * @G_MARKUP_ERROR_PARSE: document was ill-formed 0040 * @G_MARKUP_ERROR_UNKNOWN_ELEMENT: error should be set by #GMarkupParser 0041 * functions; element wasn't known 0042 * @G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE: error should be set by #GMarkupParser 0043 * functions; attribute wasn't known 0044 * @G_MARKUP_ERROR_INVALID_CONTENT: error should be set by #GMarkupParser 0045 * functions; content was invalid 0046 * @G_MARKUP_ERROR_MISSING_ATTRIBUTE: error should be set by #GMarkupParser 0047 * functions; a required attribute was missing 0048 * 0049 * Error codes returned by markup parsing. 0050 */ 0051 typedef enum 0052 { 0053 G_MARKUP_ERROR_BAD_UTF8, 0054 G_MARKUP_ERROR_EMPTY, 0055 G_MARKUP_ERROR_PARSE, 0056 /* The following are primarily intended for specific GMarkupParser 0057 * implementations to set. 0058 */ 0059 G_MARKUP_ERROR_UNKNOWN_ELEMENT, 0060 G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, 0061 G_MARKUP_ERROR_INVALID_CONTENT, 0062 G_MARKUP_ERROR_MISSING_ATTRIBUTE 0063 } GMarkupError; 0064 0065 /** 0066 * G_MARKUP_ERROR: 0067 * 0068 * Error domain for markup parsing. 0069 * Errors in this domain will be from the #GMarkupError enumeration. 0070 * See #GError for information on error domains. 0071 */ 0072 #define G_MARKUP_ERROR g_markup_error_quark () 0073 0074 GLIB_AVAILABLE_IN_ALL 0075 GQuark g_markup_error_quark (void); 0076 0077 /** 0078 * GMarkupParseFlags: 0079 * @G_MARKUP_DEFAULT_FLAGS: No special behaviour. Since: 2.74 0080 * @G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG: flag you should not use 0081 * @G_MARKUP_TREAT_CDATA_AS_TEXT: When this flag is set, CDATA marked 0082 * sections are not passed literally to the @passthrough function of 0083 * the parser. Instead, the content of the section (without the 0084 * `<![CDATA[` and `]]>`) is 0085 * passed to the @text function. This flag was added in GLib 2.12 0086 * @G_MARKUP_PREFIX_ERROR_POSITION: Normally errors caught by GMarkup 0087 * itself have line/column information prefixed to them to let the 0088 * caller know the location of the error. When this flag is set the 0089 * location information is also prefixed to errors generated by the 0090 * #GMarkupParser implementation functions 0091 * @G_MARKUP_IGNORE_QUALIFIED: Ignore (don't report) qualified 0092 * attributes and tags, along with their contents. A qualified 0093 * attribute or tag is one that contains ':' in its name (ie: is in 0094 * another namespace). Since: 2.40. 0095 * 0096 * Flags that affect the behaviour of the parser. 0097 */ 0098 typedef enum 0099 { 0100 G_MARKUP_DEFAULT_FLAGS GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0, 0101 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0, 0102 G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1, 0103 G_MARKUP_PREFIX_ERROR_POSITION = 1 << 2, 0104 G_MARKUP_IGNORE_QUALIFIED = 1 << 3 0105 } GMarkupParseFlags; 0106 0107 /** 0108 * GMarkupParseContext: 0109 * 0110 * A parse context is used to parse a stream of bytes that 0111 * you expect to contain marked-up text. 0112 * 0113 * See g_markup_parse_context_new(), #GMarkupParser, and so 0114 * on for more details. 0115 */ 0116 typedef struct _GMarkupParseContext GMarkupParseContext; 0117 typedef struct _GMarkupParser GMarkupParser; 0118 0119 /** 0120 * GMarkupParser: 0121 * @start_element: Callback to invoke when the opening tag of an element 0122 * is seen. The callback's @attribute_names and @attribute_values parameters 0123 * are %NULL-terminated. 0124 * @end_element: Callback to invoke when the closing tag of an element 0125 * is seen. Note that this is also called for empty tags like 0126 * `<empty/>`. 0127 * @text: Callback to invoke when some text is seen (text is always 0128 * inside an element). Note that the text of an element may be spread 0129 * over multiple calls of this function. If the 0130 * %G_MARKUP_TREAT_CDATA_AS_TEXT flag is set, this function is also 0131 * called for the content of CDATA marked sections. 0132 * @passthrough: Callback to invoke for comments, processing instructions 0133 * and doctype declarations; if you're re-writing the parsed document, 0134 * write the passthrough text back out in the same position. If the 0135 * %G_MARKUP_TREAT_CDATA_AS_TEXT flag is not set, this function is also 0136 * called for CDATA marked sections. 0137 * @error: Callback to invoke when an error occurs. 0138 * 0139 * Any of the fields in #GMarkupParser can be %NULL, in which case they 0140 * will be ignored. Except for the @error function, any of these callbacks 0141 * can set an error; in particular the %G_MARKUP_ERROR_UNKNOWN_ELEMENT, 0142 * %G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, and %G_MARKUP_ERROR_INVALID_CONTENT 0143 * errors are intended to be set from these callbacks. If you set an error 0144 * from a callback, g_markup_parse_context_parse() will report that error 0145 * back to its caller. 0146 * 0147 * Refer to the [GMarkup](../glib/markup.html) documentation to understand 0148 * the scope and limitations of `GMarkupParser`. In particular, it is not a 0149 * full XML parser and it must not be used to process untrusted data. 0150 */ 0151 struct _GMarkupParser 0152 { 0153 /* Called for open tags <foo bar="baz"> */ 0154 void (*start_element) (GMarkupParseContext *context, 0155 const gchar *element_name, 0156 const gchar **attribute_names, 0157 const gchar **attribute_values, 0158 gpointer user_data, 0159 GError **error); 0160 0161 /* Called for close tags </foo> */ 0162 void (*end_element) (GMarkupParseContext *context, 0163 const gchar *element_name, 0164 gpointer user_data, 0165 GError **error); 0166 0167 /* Called for character data */ 0168 /* text is not nul-terminated */ 0169 void (*text) (GMarkupParseContext *context, 0170 const gchar *text, 0171 gsize text_len, 0172 gpointer user_data, 0173 GError **error); 0174 0175 /* Called for strings that should be re-saved verbatim in this same 0176 * position, but are not otherwise interpretable. At the moment 0177 * this includes comments and processing instructions. 0178 */ 0179 /* text is not nul-terminated. */ 0180 void (*passthrough) (GMarkupParseContext *context, 0181 const gchar *passthrough_text, 0182 gsize text_len, 0183 gpointer user_data, 0184 GError **error); 0185 0186 /* Called on error, including one set by other 0187 * methods in the vtable. The GError should not be freed. 0188 */ 0189 void (*error) (GMarkupParseContext *context, 0190 GError *error, 0191 gpointer user_data); 0192 }; 0193 0194 GLIB_AVAILABLE_IN_ALL 0195 GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser, 0196 GMarkupParseFlags flags, 0197 gpointer user_data, 0198 GDestroyNotify user_data_dnotify); 0199 GLIB_AVAILABLE_IN_2_36 0200 GMarkupParseContext *g_markup_parse_context_ref (GMarkupParseContext *context); 0201 GLIB_AVAILABLE_IN_2_36 0202 void g_markup_parse_context_unref (GMarkupParseContext *context); 0203 GLIB_AVAILABLE_IN_ALL 0204 void g_markup_parse_context_free (GMarkupParseContext *context); 0205 GLIB_AVAILABLE_IN_ALL 0206 gboolean g_markup_parse_context_parse (GMarkupParseContext *context, 0207 const gchar *text, 0208 gssize text_len, 0209 GError **error); 0210 GLIB_AVAILABLE_IN_ALL 0211 void g_markup_parse_context_push (GMarkupParseContext *context, 0212 const GMarkupParser *parser, 0213 gpointer user_data); 0214 GLIB_AVAILABLE_IN_ALL 0215 gpointer g_markup_parse_context_pop (GMarkupParseContext *context); 0216 0217 GLIB_AVAILABLE_IN_ALL 0218 gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context, 0219 GError **error); 0220 GLIB_AVAILABLE_IN_ALL 0221 const gchar * g_markup_parse_context_get_element (GMarkupParseContext *context); 0222 GLIB_AVAILABLE_IN_ALL 0223 const GSList * g_markup_parse_context_get_element_stack (GMarkupParseContext *context); 0224 0225 /* For user-constructed error messages, has no precise semantics */ 0226 GLIB_AVAILABLE_IN_ALL 0227 void g_markup_parse_context_get_position (GMarkupParseContext *context, 0228 gint *line_number, 0229 gint *char_number); 0230 GLIB_AVAILABLE_IN_ALL 0231 gpointer g_markup_parse_context_get_user_data (GMarkupParseContext *context); 0232 0233 /* useful when saving */ 0234 GLIB_AVAILABLE_IN_ALL 0235 gchar* g_markup_escape_text (const gchar *text, 0236 gssize length); 0237 0238 GLIB_AVAILABLE_IN_ALL 0239 gchar *g_markup_printf_escaped (const char *format, 0240 ...) G_GNUC_PRINTF (1, 2); 0241 GLIB_AVAILABLE_IN_ALL 0242 gchar *g_markup_vprintf_escaped (const char *format, 0243 va_list args) G_GNUC_PRINTF(1, 0); 0244 0245 typedef enum 0246 { 0247 G_MARKUP_COLLECT_INVALID, 0248 G_MARKUP_COLLECT_STRING, 0249 G_MARKUP_COLLECT_STRDUP, 0250 G_MARKUP_COLLECT_BOOLEAN, 0251 G_MARKUP_COLLECT_TRISTATE, 0252 0253 G_MARKUP_COLLECT_OPTIONAL = (1 << 16) 0254 } GMarkupCollectType; 0255 0256 0257 /* useful from start_element */ 0258 GLIB_AVAILABLE_IN_ALL 0259 gboolean g_markup_collect_attributes (const gchar *element_name, 0260 const gchar **attribute_names, 0261 const gchar **attribute_values, 0262 GError **error, 0263 GMarkupCollectType first_type, 0264 const gchar *first_attr, 0265 ...); 0266 0267 G_END_DECLS 0268 0269 #endif /* __G_MARKUP_H__ */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|