You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

164 lines
6.6 KiB

  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. #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  21. #error "Only <glib.h> can be included directly."
  22. #endif
  23. #ifndef __G_MARKUP_H__
  24. #define __G_MARKUP_H__
  25. #include <stdarg.h>
  26. #include <glib/gerror.h>
  27. #include <glib/gslist.h>
  28. G_BEGIN_DECLS
  29. typedef enum
  30. {
  31. G_MARKUP_ERROR_BAD_UTF8,
  32. G_MARKUP_ERROR_EMPTY,
  33. G_MARKUP_ERROR_PARSE,
  34. /* The following are primarily intended for specific GMarkupParser
  35. * implementations to set.
  36. */
  37. G_MARKUP_ERROR_UNKNOWN_ELEMENT,
  38. G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
  39. G_MARKUP_ERROR_INVALID_CONTENT,
  40. G_MARKUP_ERROR_MISSING_ATTRIBUTE
  41. } GMarkupError;
  42. #define G_MARKUP_ERROR g_markup_error_quark ()
  43. GQuark g_markup_error_quark (void);
  44. typedef enum
  45. {
  46. G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
  47. G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
  48. G_MARKUP_PREFIX_ERROR_POSITION = 1 << 2
  49. } GMarkupParseFlags;
  50. typedef struct _GMarkupParseContext GMarkupParseContext;
  51. typedef struct _GMarkupParser GMarkupParser;
  52. struct _GMarkupParser
  53. {
  54. /* Called for open tags <foo bar="baz"> */
  55. void (*start_element) (GMarkupParseContext *context,
  56. const gchar *element_name,
  57. const gchar **attribute_names,
  58. const gchar **attribute_values,
  59. gpointer user_data,
  60. GError **error);
  61. /* Called for close tags </foo> */
  62. void (*end_element) (GMarkupParseContext *context,
  63. const gchar *element_name,
  64. gpointer user_data,
  65. GError **error);
  66. /* Called for character data */
  67. /* text is not nul-terminated */
  68. void (*text) (GMarkupParseContext *context,
  69. const gchar *text,
  70. gsize text_len,
  71. gpointer user_data,
  72. GError **error);
  73. /* Called for strings that should be re-saved verbatim in this same
  74. * position, but are not otherwise interpretable. At the moment
  75. * this includes comments and processing instructions.
  76. */
  77. /* text is not nul-terminated. */
  78. void (*passthrough) (GMarkupParseContext *context,
  79. const gchar *passthrough_text,
  80. gsize text_len,
  81. gpointer user_data,
  82. GError **error);
  83. /* Called on error, including one set by other
  84. * methods in the vtable. The GError should not be freed.
  85. */
  86. void (*error) (GMarkupParseContext *context,
  87. GError *error,
  88. gpointer user_data);
  89. };
  90. GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
  91. GMarkupParseFlags flags,
  92. gpointer user_data,
  93. GDestroyNotify user_data_dnotify);
  94. void g_markup_parse_context_free (GMarkupParseContext *context);
  95. gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
  96. const gchar *text,
  97. gssize text_len,
  98. GError **error);
  99. void g_markup_parse_context_push (GMarkupParseContext *context,
  100. const GMarkupParser *parser,
  101. gpointer user_data);
  102. gpointer g_markup_parse_context_pop (GMarkupParseContext *context);
  103. gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
  104. GError **error);
  105. G_CONST_RETURN gchar *g_markup_parse_context_get_element (GMarkupParseContext *context);
  106. G_CONST_RETURN GSList *g_markup_parse_context_get_element_stack (GMarkupParseContext *context);
  107. /* For user-constructed error messages, has no precise semantics */
  108. void g_markup_parse_context_get_position (GMarkupParseContext *context,
  109. gint *line_number,
  110. gint *char_number);
  111. gpointer g_markup_parse_context_get_user_data (GMarkupParseContext *context);
  112. /* useful when saving */
  113. gchar* g_markup_escape_text (const gchar *text,
  114. gssize length);
  115. gchar *g_markup_printf_escaped (const char *format,
  116. ...) G_GNUC_PRINTF (1, 2);
  117. gchar *g_markup_vprintf_escaped (const char *format,
  118. va_list args);
  119. typedef enum
  120. {
  121. G_MARKUP_COLLECT_INVALID,
  122. G_MARKUP_COLLECT_STRING,
  123. G_MARKUP_COLLECT_STRDUP,
  124. G_MARKUP_COLLECT_BOOLEAN,
  125. G_MARKUP_COLLECT_TRISTATE,
  126. G_MARKUP_COLLECT_OPTIONAL = (1 << 16)
  127. } GMarkupCollectType;
  128. /* useful from start_element */
  129. gboolean g_markup_collect_attributes (const gchar *element_name,
  130. const gchar **attribute_names,
  131. const gchar **attribute_values,
  132. GError **error,
  133. GMarkupCollectType first_type,
  134. const gchar *first_attr,
  135. ...);
  136. G_END_DECLS
  137. #endif /* __G_MARKUP_H__ */