/* libxml-Error.c generated by valac 0.28.1, the Vala compiler
 * generated from libxml-Error.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <libxml/xmlerror.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

/**
 * Errors for parse and writer.
 */
typedef enum  {
	GXML_ERROR_NOT_SUPPORTED,
	GXML_ERROR_PARSER,
	GXML_ERROR_WRITER
} GXmlError;
#define GXML_ERROR gxml_error_quark ()


GQuark gxml_error_quark (void);
gchar* gxml_libxml2_error_to_string (xmlError* e);
const gchar* xml_error_level_to_string (xmlErrorLevel self);
static const char* _xml_error_level_to_string (xmlErrorLevel value);


GQuark gxml_error_quark (void) {
	return g_quark_from_static_string ("gxml_error-quark");
}


static const char* _xml_error_level_to_string (xmlErrorLevel value) {
	switch (value) {
		case XML_ERR_NONE:
		return "XML_ERR_NONE";
		case XML_ERR_WARNING:
		return "XML_ERR_WARNING";
		case XML_ERR_ERROR:
		return "XML_ERR_ERROR";
		case XML_ERR_FATAL:
		return "XML_ERR_FATAL";
	}
	return NULL;
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	{
		GRegex* regex = NULL;
		const gchar* _tmp0_ = NULL;
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		GRegex* _tmp3_ = NULL;
		GRegex* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		GRegex* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		_tmp0_ = old;
		_tmp1_ = g_regex_escape_string (_tmp0_, -1);
		_tmp2_ = _tmp1_;
		_tmp3_ = g_regex_new (_tmp2_, 0, 0, &_inner_error_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		regex = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch3_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp6_ = regex;
		_tmp7_ = replacement;
		_tmp8_ = g_regex_replace_literal (_tmp6_, self, (gssize) (-1), 0, _tmp7_, 0, &_inner_error_);
		_tmp5_ = _tmp8_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch3_g_regex_error;
			}
			_g_regex_unref0 (regex);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp9_ = _tmp5_;
		_tmp5_ = NULL;
		result = _tmp9_;
		_g_free0 (_tmp5_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally3;
	__catch3_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally3:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}


gchar* gxml_libxml2_error_to_string (xmlError* e) {
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	xmlError* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp5_ = NULL;
	xmlError* _tmp6_ = NULL;
	xmlErrorLevel _tmp7_ = 0;
	const gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	xmlError* _tmp11_ = NULL;
	gint _tmp12_ = 0;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	gchar* _tmp16_ = NULL;
	xmlError* _tmp17_ = NULL;
	gint _tmp18_ = 0;
	xmlError* _tmp19_ = NULL;
	gint _tmp20_ = 0;
	xmlError* _tmp21_ = NULL;
	const gchar* _tmp22_ = NULL;
	gchar* _tmp23_ = NULL;
	gchar* _tmp24_ = NULL;
	_tmp1_ = e;
	_tmp2_ = (*_tmp1_).file;
	if (_tmp2_ == NULL) {
		_tmp0_ = "<io>";
	} else {
		xmlError* _tmp3_ = NULL;
		const gchar* _tmp4_ = NULL;
		_tmp3_ = e;
		_tmp4_ = (*_tmp3_).file;
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = _ ("%s:%s:%d: %s:%d: %s");
	_tmp6_ = e;
	_tmp7_ = (*_tmp6_).level;
	_tmp8_ = _xml_error_level_to_string (_tmp7_);
	_tmp9_ = string_replace (_tmp8_, "XML_ERR_", "");
	_tmp10_ = _tmp9_;
	_tmp11_ = e;
	_tmp12_ = (*_tmp11_).domain;
	_tmp13_ = g_strdup_printf ("%i", _tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = string_replace (_tmp14_, "XML_FROM_", "");
	_tmp16_ = _tmp15_;
	_tmp17_ = e;
	_tmp18_ = (*_tmp17_).code;
	_tmp19_ = e;
	_tmp20_ = (*_tmp19_).line;
	_tmp21_ = e;
	_tmp22_ = (*_tmp21_).message;
	_tmp23_ = g_strdup_printf (_tmp5_, _tmp10_, _tmp16_, _tmp18_, _tmp0_, _tmp20_, _tmp22_);
	_tmp24_ = _tmp23_;
	_g_free0 (_tmp16_);
	_g_free0 (_tmp14_);
	_g_free0 (_tmp10_);
	result = _tmp24_;
	return result;
}



