1 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #include <glibmm/markup.h>
4 #include <glibmm/private/markup_p.h>
9 /* Copyright (C) 2002 The gtkmm Development Team
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <glibmm/markup.h>
27 #include <glibmm/exceptionhandler.h>
28 #include <glibmm/utility.h>
38 Glib::ustring escape_text(const Glib::ustring& text)
40 const Glib::ScopedPtr<char> buf (g_markup_escape_text(text.data(), text.bytes()));
41 return Glib::ustring(buf.get());
45 /**** Glib::Markup::AttributeKeyLess ***************************************/
47 bool AttributeKeyLess::operator()(const Glib::ustring& lhs, const Glib::ustring& rhs) const
49 return (lhs.raw() < rhs.raw());
53 /**** Glib::Markup::ParserCallbacks ****************************************/
58 static const GMarkupParser vfunc_table;
60 static void start_element(GMarkupParseContext* context,
61 const char* element_name,
62 const char** attribute_names,
63 const char** attribute_values,
67 static void end_element(GMarkupParseContext* context,
68 const char* element_name,
72 static void text(GMarkupParseContext* context,
78 static void passthrough(GMarkupParseContext* context,
79 const char* passthrough_text,
84 static void error(GMarkupParseContext* context,
90 const GMarkupParser ParserCallbacks::vfunc_table =
92 &ParserCallbacks::start_element,
93 &ParserCallbacks::end_element,
94 &ParserCallbacks::text,
95 &ParserCallbacks::passthrough,
96 &ParserCallbacks::error,
99 void ParserCallbacks::start_element(GMarkupParseContext* context,
100 const char* element_name,
101 const char** attribute_names,
102 const char** attribute_values,
106 ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
107 g_return_if_fail(context == cpp_context.gobj());
111 Parser::AttributeMap attributes;
113 if(attribute_names && attribute_values)
115 const char *const * pname = attribute_names;
116 const char *const * pvalue = attribute_values;
118 for(; *pname && *pvalue; ++pname, ++pvalue)
119 attributes.insert(Parser::AttributeMap::value_type(*pname, *pvalue));
121 g_return_if_fail(*pname == 0 && *pvalue == 0);
124 cpp_context.get_parser()->on_start_element(cpp_context, element_name, attributes);
126 catch(MarkupError& err)
128 err.propagate(error);
132 Glib::exception_handlers_invoke();
136 void ParserCallbacks::end_element(GMarkupParseContext* context,
137 const char* element_name,
141 ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
142 g_return_if_fail(context == cpp_context.gobj());
146 cpp_context.get_parser()->on_end_element(cpp_context, element_name);
148 catch(MarkupError& err)
150 err.propagate(error);
154 Glib::exception_handlers_invoke();
158 void ParserCallbacks::text(GMarkupParseContext* context,
164 ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
165 g_return_if_fail(context == cpp_context.gobj());
169 cpp_context.get_parser()->on_text(cpp_context, Glib::ustring(text, text + text_len));
171 catch(MarkupError& err)
173 err.propagate(error);
177 Glib::exception_handlers_invoke();
181 void ParserCallbacks::passthrough(GMarkupParseContext* context,
182 const char* passthrough_text,
187 ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
188 g_return_if_fail(context == cpp_context.gobj());
192 cpp_context.get_parser()->on_passthrough(
193 cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len));
195 catch(MarkupError& err)
197 err.propagate(error);
201 Glib::exception_handlers_invoke();
205 void ParserCallbacks::error(GMarkupParseContext* context,
209 ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
211 g_return_if_fail(context == cpp_context.gobj());
212 g_return_if_fail(error->domain == G_MARKUP_ERROR);
216 cpp_context.get_parser()->on_error(cpp_context, MarkupError(g_error_copy(error)));
220 Glib::exception_handlers_invoke();
225 /**** Glib::Markup::Parser *************************************************/
233 void Parser::on_start_element(ParseContext&, const Glib::ustring&, const Parser::AttributeMap&)
236 void Parser::on_end_element(ParseContext&, const Glib::ustring&)
239 void Parser::on_text(ParseContext&, const Glib::ustring&)
242 void Parser::on_passthrough(ParseContext&, const Glib::ustring&)
245 void Parser::on_error(ParseContext&, const MarkupError&)
249 /**** Glib::Markup::ParseContext *******************************************/
251 ParseContext::ParseContext(Parser& parser, ParseFlags flags)
254 gobject_ (g_markup_parse_context_new(&ParserCallbacks::vfunc_table, (GMarkupParseFlags) flags,
255 this, &ParseContext::destroy_notify_callback))
258 ParseContext::~ParseContext()
261 g_markup_parse_context_free(gobject_);
264 void ParseContext::parse(const Glib::ustring& text)
267 g_markup_parse_context_parse(gobject_, text.data(), text.bytes(), &error);
270 Glib::Error::throw_exception(error);
273 void ParseContext::parse(const char* text_begin, const char* text_end)
276 g_markup_parse_context_parse(gobject_, text_begin, text_end - text_begin, &error);
279 Glib::Error::throw_exception(error);
282 void ParseContext::end_parse()
285 g_markup_parse_context_end_parse(gobject_, &error);
288 Glib::Error::throw_exception(error);
291 Glib::ustring ParseContext::get_element() const
293 const char *const element_name = g_markup_parse_context_get_element(gobject_);
294 return (element_name) ? Glib::ustring(element_name) : Glib::ustring();
297 int ParseContext::get_line_number() const
300 g_markup_parse_context_get_position(gobject_, &line_number, 0);
304 int ParseContext::get_char_number() const
307 g_markup_parse_context_get_position(gobject_, 0, &char_number);
312 void ParseContext::destroy_notify_callback(void* data)
314 ParseContext *const self = static_cast<ParseContext*>(data);
316 // Detect premature destruction.
317 g_return_if_fail(self->parser_ == 0);
320 } // namespace Markup
327 } // anonymous namespace
330 Glib::MarkupError::MarkupError(Glib::MarkupError::Code error_code, const Glib::ustring& error_message)
332 Glib::Error (G_MARKUP_ERROR, error_code, error_message)
335 Glib::MarkupError::MarkupError(GError* gobject)
337 Glib::Error (gobject)
340 Glib::MarkupError::Code Glib::MarkupError::code() const
342 return static_cast<Code>(Glib::Error::code());
345 void Glib::MarkupError::throw_func(GError* gobject)
347 throw Glib::MarkupError(gobject);