Use <envar>, not <envvar>.
[platform/upstream/glib.git] / glib / 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 <glib/gerror.h>
25
26 G_BEGIN_DECLS
27
28 typedef enum
29 {
30   G_MARKUP_ERROR_BAD_UTF8,
31   G_MARKUP_ERROR_EMPTY,
32   G_MARKUP_ERROR_PARSE,
33   /* These three are primarily intended for specific GMarkupParser
34    * implementations to set.
35    */
36   G_MARKUP_ERROR_UNKNOWN_ELEMENT,
37   G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
38   G_MARKUP_ERROR_INVALID_CONTENT
39 } GMarkupError;
40
41 #define G_MARKUP_ERROR g_markup_error_quark ()
42
43 GQuark g_markup_error_quark ();
44
45 typedef enum
46 {
47   /* Hmm, can't think of any at the moment */
48   G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0
49   
50 } GMarkupParseFlags;
51
52 typedef struct _GMarkupParseContext GMarkupParseContext;
53 typedef struct _GMarkupParser GMarkupParser;
54
55 struct _GMarkupParser
56 {
57   /* Called for open tags <foo bar="baz"> */
58   void (*start_element)  (GMarkupParseContext *context,
59                           const gchar         *element_name,
60                           const gchar        **attribute_names,
61                           const gchar        **attribute_values,
62                           gpointer             user_data,
63                           GError             **error);
64
65   /* Called for close tags </foo> */
66   void (*end_element)    (GMarkupParseContext *context,
67                           const gchar         *element_name,
68                           gpointer             user_data,
69                           GError             **error);
70
71   /* Called for character data */
72   /* text is not nul-terminated */
73   void (*text)           (GMarkupParseContext *context,
74                           const gchar         *text,
75                           gsize                text_len,  
76                           gpointer             user_data,
77                           GError             **error);
78
79   /* Called for strings that should be re-saved verbatim in this same
80    * position, but are not otherwise interpretable.  At the moment
81    * this includes comments and processing instructions.
82    */
83   /* text is not nul-terminated. */
84   void (*passthrough)    (GMarkupParseContext *context,
85                           const gchar         *passthrough_text,
86                           gsize                text_len,  
87                           gpointer             user_data,
88                           GError             **error);
89
90   /* Called on error, including one set by other
91    * methods in the vtable. The GError should not be freed.
92    */
93   void (*error)          (GMarkupParseContext *context,
94                           GError              *error,
95                           gpointer             user_data);
96 };
97
98 GMarkupParseContext *g_markup_parse_context_new   (const GMarkupParser *parser,
99                                                    GMarkupParseFlags    flags,
100                                                    gpointer             user_data,
101                                                    GDestroyNotify       user_data_dnotify);
102 void                 g_markup_parse_context_free  (GMarkupParseContext *context);
103 gboolean             g_markup_parse_context_parse (GMarkupParseContext *context,
104                                                    const gchar         *text,
105                                                    gssize               text_len,  
106                                                    GError             **error);
107                                                    
108 gboolean             g_markup_parse_context_end_parse (GMarkupParseContext *context,
109                                                        GError             **error);
110
111 /* For user-constructed error messages, has no precise semantics */
112 void                 g_markup_parse_context_get_position (GMarkupParseContext *context,
113                                                           gint                *line_number,
114                                                           gint                *char_number);
115
116 /* useful when saving */
117 gchar* g_markup_escape_text (const gchar *text,
118                              gssize       length);  
119
120 G_END_DECLS
121
122 #endif /* __G_MARKUP_H__ */
123