/* xml.c generated by valac 0.56.17, the Vala compiler
 * generated from xml.vala, do not modify */

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define PDFPC_TYPE_XML_PARSER (pdfpc_xml_parser_get_type ())
#define PDFPC_XML_PARSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDFPC_TYPE_XML_PARSER, pdfpcXmlParser))
#define PDFPC_XML_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDFPC_TYPE_XML_PARSER, pdfpcXmlParserClass))
#define PDFPC_IS_XML_PARSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PDFPC_TYPE_XML_PARSER))
#define PDFPC_IS_XML_PARSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDFPC_TYPE_XML_PARSER))
#define PDFPC_XML_PARSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDFPC_TYPE_XML_PARSER, pdfpcXmlParserClass))

typedef struct _pdfpcXmlParser pdfpcXmlParser;
typedef struct _pdfpcXmlParserClass pdfpcXmlParserClass;
typedef struct _pdfpcXmlParserPrivate pdfpcXmlParserPrivate;
enum  {
	PDFPC_XML_PARSER_0_PROPERTY,
	PDFPC_XML_PARSER_NUM_PROPERTIES
};
static GParamSpec* pdfpc_xml_parser_properties[PDFPC_XML_PARSER_NUM_PROPERTIES];
typedef void (*GMarkupParserStartElementFunc) (GMarkupParseContext* context, const gchar* element_name, gchar** attribute_names, gchar** attribute_values, gpointer user_data, GError** error);
typedef void (*GMarkupParserEndElementFunc) (GMarkupParseContext* context, const gchar* element_name, gpointer user_data, GError** error);
typedef void (*GMarkupParserTextFunc) (GMarkupParseContext* context, const gchar* text, gsize text_len, gpointer user_data, GError** error);
#define _g_markup_parse_context_unref0(var) ((var == NULL) ? NULL : (var = (g_markup_parse_context_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _pdfpcXmlParser {
	GObject parent_instance;
	pdfpcXmlParserPrivate * priv;
};

struct _pdfpcXmlParserClass {
	GObjectClass parent_class;
};

struct _pdfpcXmlParserPrivate {
	GMarkupParseContext* context;
	gchar* text_buffer;
};

static gint pdfpcXmlParser_private_offset;
static gpointer pdfpc_xml_parser_parent_class = NULL;
static GeeHashMap* pdfpc_xml_parser_tags;
static GeeHashMap* pdfpc_xml_parser_tags = NULL;

VALA_EXTERN GType pdfpc_xml_parser_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (pdfpcXmlParser, g_object_unref)
static void pdfpc_xml_parser_start (pdfpcXmlParser* self,
                             GMarkupParseContext* context,
                             const gchar* name,
                             gchar** attr_names,
                             gint attr_names_length1,
                             gchar** attr_values,
                             gint attr_values_length1,
                             GError** error);
static void _pdfpc_xml_parser_start_gmarkup_parser_start_element_func (GMarkupParseContext* context,
                                                                const gchar* element_name,
                                                                gchar** attribute_names,
                                                                gchar** attribute_values,
                                                                gpointer self,
                                                                GError** error);
static void pdfpc_xml_parser_end (pdfpcXmlParser* self,
                           GMarkupParseContext* context,
                           const gchar* name,
                           GError** error);
static void _pdfpc_xml_parser_end_gmarkup_parser_end_element_func (GMarkupParseContext* context,
                                                            const gchar* element_name,
                                                            gpointer self,
                                                            GError** error);
static void pdfpc_xml_parser_text (pdfpcXmlParser* self,
                            GMarkupParseContext* context,
                            const gchar* text,
                            gsize text_len,
                            GError** error);
static void _pdfpc_xml_parser_text_gmarkup_parser_text_func (GMarkupParseContext* context,
                                                      const gchar* text,
                                                      gsize text_len,
                                                      gpointer self,
                                                      GError** error);
static void pdfpc_xml_parser_destroy (pdfpcXmlParser* self);
VALA_EXTERN GeeHashMap* pdfpc_xml_parser_parse (pdfpcXmlParser* self,
                                    const gchar* content,
                                    GError** error);
VALA_EXTERN pdfpcXmlParser* pdfpc_xml_parser_new (void);
VALA_EXTERN pdfpcXmlParser* pdfpc_xml_parser_construct (GType object_type);
static GObject * pdfpc_xml_parser_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void _pdfpc_xml_parser_destroy_gdestroy_notify (void* data);
static void pdfpc_xml_parser_finalize (GObject * obj);
static GType pdfpc_xml_parser_get_type_once (void);
static gssize _vala_array_length (gpointer array);

static const GMarkupParser PDFPC_XML_PARSER_parser = {_pdfpc_xml_parser_start_gmarkup_parser_start_element_func, _pdfpc_xml_parser_end_gmarkup_parser_end_element_func, _pdfpc_xml_parser_text_gmarkup_parser_text_func, NULL, NULL};

static inline gpointer
pdfpc_xml_parser_get_instance_private (pdfpcXmlParser* self)
{
	return G_STRUCT_MEMBER_P (self, pdfpcXmlParser_private_offset);
}

static void
_pdfpc_xml_parser_start_gmarkup_parser_start_element_func (GMarkupParseContext* context,
                                                           const gchar* element_name,
                                                           gchar** attribute_names,
                                                           gchar** attribute_values,
                                                           gpointer self,
                                                           GError** error)
{
	pdfpc_xml_parser_start ((pdfpcXmlParser*) self, context, element_name, attribute_names, _vala_array_length (attribute_names), attribute_values, _vala_array_length (attribute_values), error);
}

static void
_pdfpc_xml_parser_end_gmarkup_parser_end_element_func (GMarkupParseContext* context,
                                                       const gchar* element_name,
                                                       gpointer self,
                                                       GError** error)
{
	pdfpc_xml_parser_end ((pdfpcXmlParser*) self, context, element_name, error);
}

static void
_pdfpc_xml_parser_text_gmarkup_parser_text_func (GMarkupParseContext* context,
                                                 const gchar* text,
                                                 gsize text_len,
                                                 gpointer self,
                                                 GError** error)
{
	pdfpc_xml_parser_text ((pdfpcXmlParser*) self, context, text, text_len, error);
}

static void
pdfpc_xml_parser_destroy (pdfpcXmlParser* self)
{
	g_return_if_fail (self != NULL);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

GeeHashMap*
pdfpc_xml_parser_parse (pdfpcXmlParser* self,
                        const gchar* content,
                        GError** error)
{
	GMarkupParseContext* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* _tmp2_;
	GError* _inner_error0_ = NULL;
	GeeHashMap* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (content != NULL, NULL);
	_tmp0_ = self->priv->context;
	g_markup_parse_context_parse (_tmp0_, content, (gssize) -1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_MARKUP_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_tmp1_ = pdfpc_xml_parser_tags;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

static void
pdfpc_xml_parser_start (pdfpcXmlParser* self,
                        GMarkupParseContext* context,
                        const gchar* name,
                        gchar** attr_names,
                        gint attr_names_length1,
                        gchar** attr_values,
                        gint attr_values_length1,
                        GError** error)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = g_strdup ("");
	_g_free0 (self->priv->text_buffer);
	self->priv->text_buffer = _tmp0_;
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static void
pdfpc_xml_parser_end (pdfpcXmlParser* self,
                      GMarkupParseContext* context,
                      const gchar* name,
                      GError** error)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	g_return_if_fail (name != NULL);
	if (g_str_has_prefix (name, "pdfpc:")) {
		GeeHashMap* _tmp0_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		const gchar* _tmp3_;
		_tmp0_ = pdfpc_xml_parser_tags;
		_tmp1_ = string_substring (name, (glong) 6, (glong) -1);
		_tmp2_ = _tmp1_;
		_tmp3_ = self->priv->text_buffer;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, _tmp2_, _tmp3_);
		_g_free0 (_tmp2_);
	}
}

static void
pdfpc_xml_parser_text (pdfpcXmlParser* self,
                       GMarkupParseContext* context,
                       const gchar* text,
                       gsize text_len,
                       GError** error)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (context != NULL);
	g_return_if_fail (text != NULL);
	if (text_len > ((gsize) 0)) {
		const gchar* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = self->priv->text_buffer;
		_tmp1_ = g_strconcat (_tmp0_, text, NULL);
		_g_free0 (self->priv->text_buffer);
		self->priv->text_buffer = _tmp1_;
	}
}

pdfpcXmlParser*
pdfpc_xml_parser_construct (GType object_type)
{
	pdfpcXmlParser * self = NULL;
	self = (pdfpcXmlParser*) g_object_new (object_type, NULL);
	return self;
}

pdfpcXmlParser*
pdfpc_xml_parser_new (void)
{
	return pdfpc_xml_parser_construct (PDFPC_TYPE_XML_PARSER);
}

static void
_pdfpc_xml_parser_destroy_gdestroy_notify (void* data)
{
	pdfpc_xml_parser_destroy (data);
}

static GObject *
pdfpc_xml_parser_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	pdfpcXmlParser * self;
	GMarkupParseContext* _tmp0_;
	GeeHashMap* _tmp1_;
	parent_class = G_OBJECT_CLASS (pdfpc_xml_parser_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PDFPC_TYPE_XML_PARSER, pdfpcXmlParser);
	_tmp0_ = g_markup_parse_context_new (&PDFPC_XML_PARSER_parser, 0, self, _pdfpc_xml_parser_destroy_gdestroy_notify);
	_g_markup_parse_context_unref0 (self->priv->context);
	self->priv->context = _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (pdfpc_xml_parser_tags);
	pdfpc_xml_parser_tags = _tmp1_;
	return obj;
}

static void
pdfpc_xml_parser_class_init (pdfpcXmlParserClass * klass,
                             gpointer klass_data)
{
	pdfpc_xml_parser_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &pdfpcXmlParser_private_offset);
	G_OBJECT_CLASS (klass)->constructor = pdfpc_xml_parser_constructor;
	G_OBJECT_CLASS (klass)->finalize = pdfpc_xml_parser_finalize;
}

static void
pdfpc_xml_parser_instance_init (pdfpcXmlParser * self,
                                gpointer klass)
{
	self->priv = pdfpc_xml_parser_get_instance_private (self);
	self->priv->text_buffer = NULL;
}

static void
pdfpc_xml_parser_finalize (GObject * obj)
{
	pdfpcXmlParser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PDFPC_TYPE_XML_PARSER, pdfpcXmlParser);
	_g_markup_parse_context_unref0 (self->priv->context);
	_g_free0 (self->priv->text_buffer);
	G_OBJECT_CLASS (pdfpc_xml_parser_parent_class)->finalize (obj);
}

static GType
pdfpc_xml_parser_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (pdfpcXmlParserClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) pdfpc_xml_parser_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (pdfpcXmlParser), 0, (GInstanceInitFunc) pdfpc_xml_parser_instance_init, NULL };
	GType pdfpc_xml_parser_type_id;
	pdfpc_xml_parser_type_id = g_type_register_static (G_TYPE_OBJECT, "pdfpcXmlParser", &g_define_type_info, 0);
	pdfpcXmlParser_private_offset = g_type_add_instance_private (pdfpc_xml_parser_type_id, sizeof (pdfpcXmlParserPrivate));
	return pdfpc_xml_parser_type_id;
}

GType
pdfpc_xml_parser_get_type (void)
{
	static volatile gsize pdfpc_xml_parser_type_id__once = 0;
	if (g_once_init_enter (&pdfpc_xml_parser_type_id__once)) {
		GType pdfpc_xml_parser_type_id;
		pdfpc_xml_parser_type_id = pdfpc_xml_parser_get_type_once ();
		g_once_init_leave (&pdfpc_xml_parser_type_id__once, pdfpc_xml_parser_type_id);
	}
	return pdfpc_xml_parser_type_id__once;
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

