Major change in API for creating sources to handle multiple main loops
[platform/upstream/glib.git] / gmarkup.h
1 /* gmarkup.h - Simple XML-like string parser/writer
2  *
3  *  Copyright 2000 Red Hat, Inc.
4  *
5  * GLib is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * GLib 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 GLib; see the file COPYING.LIB.  If not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  *   Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __G_MARKUP_H__
22 #define __G_MARKUP_H__
23
24 #include <gerror.h>
25
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30
31 typedef enum
32 {
33   G_MARKUP_ERROR_BAD_UTF8,
34   G_MARKUP_ERROR_EMPTY,
35   G_MARKUP_ERROR_PARSE,
36   /* These three are primarily intended for specific GMarkupParser
37    * implementations to set.
38    */
39   G_MARKUP_ERROR_UNKNOWN_ELEMENT,
40   G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
41   G_MARKUP_ERROR_INVALID_CONTENT
42 } GMarkupError;
43
44 #define G_MARKUP_ERROR g_markup_error_quark ()
45
46 GQuark g_markup_error_quark ();
47
48 typedef enum
49 {
50   /* Hmm, can't think of any at the moment */
51   G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0
52   
53 } GMarkupParseFlags;
54
55 typedef struct _GMarkupParseContext GMarkupParseContext;
56 typedef struct _GMarkupParser GMarkupParser;
57
58 struct _GMarkupParser
59 {
60   /* Called for open tags <foo bar="baz"> */
61   void (*start_element)  (GMarkupParseContext *context,
62                           const gchar         *element_name,
63                           const gchar        **attribute_names,
64                           const gchar        **attribute_values,
65                           gpointer             user_data,
66                           GError             **error);
67
68   /* Called for close tags </foo> */
69   void (*end_element)    (GMarkupParseContext *context,
70                           const gchar         *element_name,
71                           gpointer             user_data,
72                           GError             **error);
73
74   /* Called for character data */
75   /* text is not nul-terminated */
76   void (*text)           (GMarkupParseContext *context,
77                           const gchar         *text,
78                           gint                 text_len,
79                           gpointer             user_data,
80                           GError             **error);
81
82   /* Called for strings that should be re-saved verbatim in this same
83    * position, but are not otherwise interpretable.  At the moment
84    * this includes comments and processing instructions.
85    */
86   /* text is not nul-terminated. */
87   void (*passthrough)    (GMarkupParseContext *context,
88                           const gchar         *passthrough_text,
89                           gint                 text_len,
90                           gpointer             user_data,
91                           GError             **error);
92
93   /* Called on error, including one set by other
94    * methods in the vtable. The GError should not be freed.
95    */
96   void (*error)          (GMarkupParseContext *context,
97                           GError              *error,
98                           gpointer             user_data);
99 };
100
101 GMarkupParseContext *g_markup_parse_context_new   (const GMarkupParser *parser,
102                                                    GMarkupParseFlags    flags,
103                                                    gpointer             user_data,
104                                                    GDestroyNotify       user_data_dnotify);
105 void                 g_markup_parse_context_free  (GMarkupParseContext *context);
106 gboolean             g_markup_parse_context_parse (GMarkupParseContext *context,
107                                                    const gchar         *text,
108                                                    gint                 text_len,
109                                                    GError             **error);
110                                                    
111 gboolean             g_markup_parse_context_end_parse (GMarkupParseContext *context,
112                                                        GError             **error);
113
114 /* For user-constructed error messages, has no precise semantics */
115 void                 g_markup_parse_context_get_position (GMarkupParseContext *context,
116                                                           gint                *line_number,
117                                                           gint                *char_number);
118
119 /* useful when saving */
120 gchar* g_markup_escape_text (const gchar *text,
121                              gint         length);
122
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif /* __G_MARKUP_H__ */
129