1 gmarkup.h |
1 /* gmarkup.h - Simple XML-like string parser/writer |
|
2 * |
|
3 * Copyright 2000 Red Hat, Inc. |
|
4 * Portions copyright (c) 2006 Nokia Corporation. All rights reserved. |
|
5 * |
|
6 * GLib is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU Lesser General Public License as |
|
8 * published by the Free Software Foundation; either version 2 of the |
|
9 * License, or (at your option) any later version. |
|
10 * |
|
11 * GLib is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * Lesser General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU Lesser General Public |
|
17 * License along with GLib; see the file COPYING.LIB. If not, |
|
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
19 * Boston, MA 02111-1307, USA. |
|
20 */ |
|
21 |
|
22 #ifndef __G_MARKUP_H__ |
|
23 #define __G_MARKUP_H__ |
|
24 |
|
25 #include <_ansi.h> |
|
26 #include <stdarg.h> |
|
27 |
|
28 #include <glib/gerror.h> |
|
29 |
|
30 G_BEGIN_DECLS |
|
31 |
|
32 typedef enum |
|
33 { |
|
34 G_MARKUP_ERROR_BAD_UTF8, |
|
35 G_MARKUP_ERROR_EMPTY, |
|
36 G_MARKUP_ERROR_PARSE, |
|
37 /* These three are primarily intended for specific GMarkupParser |
|
38 * implementations to set. |
|
39 */ |
|
40 G_MARKUP_ERROR_UNKNOWN_ELEMENT, |
|
41 G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, |
|
42 G_MARKUP_ERROR_INVALID_CONTENT |
|
43 } GMarkupError; |
|
44 |
|
45 #define G_MARKUP_ERROR g_markup_error_quark () |
|
46 |
|
47 IMPORT_C GQuark g_markup_error_quark (void); |
|
48 |
|
49 typedef enum |
|
50 { |
|
51 /* Hmm, can't think of any at the moment */ |
|
52 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0 |
|
53 |
|
54 } GMarkupParseFlags; |
|
55 |
|
56 typedef struct _GMarkupParseContext GMarkupParseContext; |
|
57 typedef struct _GMarkupParser GMarkupParser; |
|
58 |
|
59 struct _GMarkupParser |
|
60 { |
|
61 /* Called for open tags <foo bar="baz"> */ |
|
62 void (*start_element) (GMarkupParseContext *context, |
|
63 const gchar *element_name, |
|
64 const gchar **attribute_names, |
|
65 const gchar **attribute_values, |
|
66 gpointer user_data, |
|
67 GError **error); |
|
68 |
|
69 /* Called for close tags </foo> */ |
|
70 void (*end_element) (GMarkupParseContext *context, |
|
71 const gchar *element_name, |
|
72 gpointer user_data, |
|
73 GError **error); |
|
74 |
|
75 /* Called for character data */ |
|
76 /* text is not nul-terminated */ |
|
77 void (*text) (GMarkupParseContext *context, |
|
78 const gchar *text, |
|
79 gsize text_len, |
|
80 gpointer user_data, |
|
81 GError **error); |
|
82 |
|
83 /* Called for strings that should be re-saved verbatim in this same |
|
84 * position, but are not otherwise interpretable. At the moment |
|
85 * this includes comments and processing instructions. |
|
86 */ |
|
87 /* text is not nul-terminated. */ |
|
88 void (*passthrough) (GMarkupParseContext *context, |
|
89 const gchar *passthrough_text, |
|
90 gsize text_len, |
|
91 gpointer user_data, |
|
92 GError **error); |
|
93 |
|
94 /* Called on error, including one set by other |
|
95 * methods in the vtable. The GError should not be freed. |
|
96 */ |
|
97 void (*error) (GMarkupParseContext *context, |
|
98 GError *error, |
|
99 gpointer user_data); |
|
100 }; |
|
101 |
|
102 IMPORT_C GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser, |
|
103 GMarkupParseFlags flags, |
|
104 gpointer user_data, |
|
105 GDestroyNotify user_data_dnotify); |
|
106 IMPORT_C void g_markup_parse_context_free (GMarkupParseContext *context); |
|
107 IMPORT_C gboolean g_markup_parse_context_parse (GMarkupParseContext *context, |
|
108 const gchar *text, |
|
109 gssize text_len, |
|
110 GError **error); |
|
111 |
|
112 IMPORT_C gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context, |
|
113 GError **error); |
|
114 IMPORT_C G_CONST_RETURN gchar *g_markup_parse_context_get_element (GMarkupParseContext *context); |
|
115 |
|
116 /* For user-constructed error messages, has no precise semantics */ |
|
117 IMPORT_C void g_markup_parse_context_get_position (GMarkupParseContext *context, |
|
118 gint *line_number, |
|
119 gint *char_number); |
|
120 |
|
121 /* useful when saving */ |
|
122 IMPORT_C gchar* g_markup_escape_text (const gchar *text, |
|
123 gssize length); |
|
124 |
|
125 IMPORT_C gchar *g_markup_printf_escaped (const char *format, |
|
126 ...) G_GNUC_PRINTF (1, 2); |
|
127 IMPORT_C gchar *g_markup_vprintf_escaped (const char *format, |
|
128 va_list args); |
|
129 |
|
130 G_END_DECLS |
|
131 |
|
132 #endif /* __G_MARKUP_H__ */ |
|
133 |