Blame glib/gmarkup.h

Packit ae235b
/* gmarkup.h - Simple XML-like string parser/writer
Packit ae235b
 *
Packit ae235b
 *  Copyright 2000 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public License
Packit ae235b
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#ifndef __G_MARKUP_H__
Packit ae235b
#define __G_MARKUP_H__
Packit ae235b
Packit ae235b
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
Packit ae235b
#error "Only <glib.h> can be included directly."
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <stdarg.h>
Packit ae235b
Packit ae235b
#include <glib/gerror.h>
Packit ae235b
#include <glib/gslist.h>
Packit ae235b
Packit ae235b
G_BEGIN_DECLS
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GMarkupError:
Packit ae235b
 * @G_MARKUP_ERROR_BAD_UTF8: text being parsed was not valid UTF-8
Packit ae235b
 * @G_MARKUP_ERROR_EMPTY: document contained nothing, or only whitespace
Packit ae235b
 * @G_MARKUP_ERROR_PARSE: document was ill-formed
Packit ae235b
 * @G_MARKUP_ERROR_UNKNOWN_ELEMENT: error should be set by #GMarkupParser
Packit ae235b
 *     functions; element wasn't known
Packit ae235b
 * @G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE: error should be set by #GMarkupParser
Packit ae235b
 *     functions; attribute wasn't known
Packit ae235b
 * @G_MARKUP_ERROR_INVALID_CONTENT: error should be set by #GMarkupParser
Packit ae235b
 *     functions; content was invalid
Packit ae235b
 * @G_MARKUP_ERROR_MISSING_ATTRIBUTE: error should be set by #GMarkupParser
Packit ae235b
 *     functions; a required attribute was missing
Packit ae235b
 *
Packit ae235b
 * Error codes returned by markup parsing.
Packit ae235b
 */
Packit ae235b
typedef enum
Packit ae235b
{
Packit ae235b
  G_MARKUP_ERROR_BAD_UTF8,
Packit ae235b
  G_MARKUP_ERROR_EMPTY,
Packit ae235b
  G_MARKUP_ERROR_PARSE,
Packit ae235b
  /* The following are primarily intended for specific GMarkupParser
Packit ae235b
   * implementations to set.
Packit ae235b
   */
Packit ae235b
  G_MARKUP_ERROR_UNKNOWN_ELEMENT,
Packit ae235b
  G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
Packit ae235b
  G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
  G_MARKUP_ERROR_MISSING_ATTRIBUTE
Packit ae235b
} GMarkupError;
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_MARKUP_ERROR:
Packit ae235b
 *
Packit ae235b
 * Error domain for markup parsing.
Packit ae235b
 * Errors in this domain will be from the #GMarkupError enumeration.
Packit ae235b
 * See #GError for information on error domains.
Packit ae235b
 */
Packit ae235b
#define G_MARKUP_ERROR g_markup_error_quark ()
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GQuark g_markup_error_quark (void);
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GMarkupParseFlags:
Packit ae235b
 * @G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG: flag you should not use
Packit ae235b
 * @G_MARKUP_TREAT_CDATA_AS_TEXT: When this flag is set, CDATA marked
Packit ae235b
 *     sections are not passed literally to the @passthrough function of
Packit ae235b
 *     the parser. Instead, the content of the section (without the
Packit ae235b
 *     ``) is
Packit ae235b
 *     passed to the @text function. This flag was added in GLib 2.12
Packit ae235b
 * @G_MARKUP_PREFIX_ERROR_POSITION: Normally errors caught by GMarkup
Packit ae235b
 *     itself have line/column information prefixed to them to let the
Packit ae235b
 *     caller know the location of the error. When this flag is set the
Packit ae235b
 *     location information is also prefixed to errors generated by the
Packit ae235b
 *     #GMarkupParser implementation functions
Packit ae235b
 * @G_MARKUP_IGNORE_QUALIFIED: Ignore (don't report) qualified
Packit ae235b
 *     attributes and tags, along with their contents.  A qualified
Packit ae235b
 *     attribute or tag is one that contains ':' in its name (ie: is in
Packit ae235b
 *     another namespace).  Since: 2.40.
Packit ae235b
 *
Packit ae235b
 * Flags that affect the behaviour of the parser.
Packit ae235b
 */
Packit ae235b
typedef enum
Packit ae235b
{
Packit ae235b
  G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
Packit ae235b
  G_MARKUP_TREAT_CDATA_AS_TEXT              = 1 << 1,
Packit ae235b
  G_MARKUP_PREFIX_ERROR_POSITION            = 1 << 2,
Packit ae235b
  G_MARKUP_IGNORE_QUALIFIED                 = 1 << 3
Packit ae235b
} GMarkupParseFlags;
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GMarkupParseContext:
Packit ae235b
 *
Packit ae235b
 * A parse context is used to parse a stream of bytes that
Packit ae235b
 * you expect to contain marked-up text.
Packit ae235b
 *
Packit ae235b
 * See g_markup_parse_context_new(), #GMarkupParser, and so
Packit ae235b
 * on for more details.
Packit ae235b
 */
Packit ae235b
typedef struct _GMarkupParseContext GMarkupParseContext;
Packit ae235b
typedef struct _GMarkupParser GMarkupParser;
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GMarkupParser:
Packit ae235b
 * @start_element: Callback to invoke when the opening tag of an element
Packit ae235b
 *     is seen. The callback's @attribute_names and @attribute_values parameters
Packit ae235b
 *     are %NULL-terminated.
Packit ae235b
 * @end_element: Callback to invoke when the closing tag of an element
Packit ae235b
 *     is seen. Note that this is also called for empty tags like
Packit ae235b
 *     `<empty/>`.
Packit ae235b
 * @text: Callback to invoke when some text is seen (text is always
Packit ae235b
 *     inside an element). Note that the text of an element may be spread
Packit ae235b
 *     over multiple calls of this function. If the
Packit ae235b
 *     %G_MARKUP_TREAT_CDATA_AS_TEXT flag is set, this function is also
Packit ae235b
 *     called for the content of CDATA marked sections.
Packit ae235b
 * @passthrough: Callback to invoke for comments, processing instructions
Packit ae235b
 *     and doctype declarations; if you're re-writing the parsed document,
Packit ae235b
 *     write the passthrough text back out in the same position. If the
Packit ae235b
 *     %G_MARKUP_TREAT_CDATA_AS_TEXT flag is not set, this function is also
Packit ae235b
 *     called for CDATA marked sections.
Packit ae235b
 * @error: Callback to invoke when an error occurs.
Packit ae235b
 *
Packit ae235b
 * Any of the fields in #GMarkupParser can be %NULL, in which case they
Packit ae235b
 * will be ignored. Except for the @error function, any of these callbacks
Packit ae235b
 * can set an error; in particular the %G_MARKUP_ERROR_UNKNOWN_ELEMENT,
Packit ae235b
 * %G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, and %G_MARKUP_ERROR_INVALID_CONTENT
Packit ae235b
 * errors are intended to be set from these callbacks. If you set an error
Packit ae235b
 * from a callback, g_markup_parse_context_parse() will report that error
Packit ae235b
 * back to its caller.
Packit ae235b
 */
Packit ae235b
struct _GMarkupParser
Packit ae235b
{
Packit ae235b
  /* Called for open tags <foo bar="baz"> */
Packit ae235b
  void (*start_element)  (GMarkupParseContext *context,
Packit ae235b
                          const gchar         *element_name,
Packit ae235b
                          const gchar        **attribute_names,
Packit ae235b
                          const gchar        **attribute_values,
Packit ae235b
                          gpointer             user_data,
Packit ae235b
                          GError             **error);
Packit ae235b
Packit ae235b
  /* Called for close tags </foo> */
Packit ae235b
  void (*end_element)    (GMarkupParseContext *context,
Packit ae235b
                          const gchar         *element_name,
Packit ae235b
                          gpointer             user_data,
Packit ae235b
                          GError             **error);
Packit ae235b
Packit ae235b
  /* Called for character data */
Packit ae235b
  /* text is not nul-terminated */
Packit ae235b
  void (*text)           (GMarkupParseContext *context,
Packit ae235b
                          const gchar         *text,
Packit ae235b
                          gsize                text_len,
Packit ae235b
                          gpointer             user_data,
Packit ae235b
                          GError             **error);
Packit ae235b
Packit ae235b
  /* Called for strings that should be re-saved verbatim in this same
Packit ae235b
   * position, but are not otherwise interpretable.  At the moment
Packit ae235b
   * this includes comments and processing instructions.
Packit ae235b
   */
Packit ae235b
  /* text is not nul-terminated. */
Packit ae235b
  void (*passthrough)    (GMarkupParseContext *context,
Packit ae235b
                          const gchar         *passthrough_text,
Packit ae235b
                          gsize                text_len,
Packit ae235b
                          gpointer             user_data,
Packit ae235b
                          GError             **error);
Packit ae235b
Packit ae235b
  /* Called on error, including one set by other
Packit ae235b
   * methods in the vtable. The GError should not be freed.
Packit ae235b
   */
Packit ae235b
  void (*error)          (GMarkupParseContext *context,
Packit ae235b
                          GError              *error,
Packit ae235b
                          gpointer             user_data);
Packit ae235b
};
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GMarkupParseContext *g_markup_parse_context_new   (const GMarkupParser *parser,
Packit ae235b
                                                   GMarkupParseFlags    flags,
Packit ae235b
                                                   gpointer             user_data,
Packit ae235b
                                                   GDestroyNotify       user_data_dnotify);
Packit ae235b
GLIB_AVAILABLE_IN_2_36
Packit ae235b
GMarkupParseContext *g_markup_parse_context_ref   (GMarkupParseContext *context);
Packit ae235b
GLIB_AVAILABLE_IN_2_36
Packit ae235b
void                 g_markup_parse_context_unref (GMarkupParseContext *context);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void                 g_markup_parse_context_free  (GMarkupParseContext *context);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gboolean             g_markup_parse_context_parse (GMarkupParseContext *context,
Packit ae235b
                                                   const gchar         *text,
Packit ae235b
                                                   gssize               text_len,
Packit ae235b
                                                   GError             **error);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void                 g_markup_parse_context_push  (GMarkupParseContext *context,
Packit ae235b
                                                   const GMarkupParser *parser,
Packit ae235b
                                                   gpointer             user_data);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gpointer             g_markup_parse_context_pop   (GMarkupParseContext *context);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gboolean             g_markup_parse_context_end_parse (GMarkupParseContext *context,
Packit ae235b
                                                       GError             **error);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
const gchar *        g_markup_parse_context_get_element (GMarkupParseContext *context);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
const GSList *       g_markup_parse_context_get_element_stack (GMarkupParseContext *context);
Packit ae235b
Packit ae235b
/* For user-constructed error messages, has no precise semantics */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void                 g_markup_parse_context_get_position (GMarkupParseContext *context,
Packit ae235b
                                                          gint                *line_number,
Packit ae235b
                                                          gint                *char_number);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gpointer             g_markup_parse_context_get_user_data (GMarkupParseContext *context);
Packit ae235b
Packit ae235b
/* useful when saving */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar* g_markup_escape_text (const gchar *text,
Packit ae235b
                             gssize       length);
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *g_markup_printf_escaped (const char *format,
Packit ae235b
				...) G_GNUC_PRINTF (1, 2);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gchar *g_markup_vprintf_escaped (const char *format,
Packit ae235b
				 va_list     args) G_GNUC_PRINTF(1, 0);
Packit ae235b
Packit ae235b
typedef enum
Packit ae235b
{
Packit ae235b
  G_MARKUP_COLLECT_INVALID,
Packit ae235b
  G_MARKUP_COLLECT_STRING,
Packit ae235b
  G_MARKUP_COLLECT_STRDUP,
Packit ae235b
  G_MARKUP_COLLECT_BOOLEAN,
Packit ae235b
  G_MARKUP_COLLECT_TRISTATE,
Packit ae235b
Packit ae235b
  G_MARKUP_COLLECT_OPTIONAL = (1 << 16)
Packit ae235b
} GMarkupCollectType;
Packit ae235b
Packit ae235b
Packit ae235b
/* useful from start_element */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gboolean   g_markup_collect_attributes (const gchar         *element_name,
Packit ae235b
                                        const gchar        **attribute_names,
Packit ae235b
                                        const gchar        **attribute_values,
Packit ae235b
                                        GError             **error,
Packit ae235b
                                        GMarkupCollectType   first_type,
Packit ae235b
                                        const gchar         *first_attr,
Packit ae235b
                                        ...);
Packit ae235b
Packit ae235b
G_END_DECLS
Packit ae235b
Packit ae235b
#endif /* __G_MARKUP_H__ */