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

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libxml/HTMLtree.h>
#include <libxml/HTMLparser.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <gobject/gvaluecollector.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 TUBA_UTILS_TYPE_HTMLX (tuba_utils_htmlx_get_type ())
#define TUBA_UTILS_HTMLX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TUBA_UTILS_TYPE_HTMLX, TubaUtilsHtmlx))
#define TUBA_UTILS_HTMLX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TUBA_UTILS_TYPE_HTMLX, TubaUtilsHtmlxClass))
#define TUBA_UTILS_IS_HTMLX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TUBA_UTILS_TYPE_HTMLX))
#define TUBA_UTILS_IS_HTMLX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TUBA_UTILS_TYPE_HTMLX))
#define TUBA_UTILS_HTMLX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TUBA_UTILS_TYPE_HTMLX, TubaUtilsHtmlxClass))

typedef struct _TubaUtilsHtmlx TubaUtilsHtmlx;
typedef struct _TubaUtilsHtmlxClass TubaUtilsHtmlxClass;
typedef struct _TubaUtilsHtmlxPrivate TubaUtilsHtmlxPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _xmlFreeDoc0(var) ((var == NULL) ? NULL : (var = (xmlFreeDoc (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _TubaUtilsParamSpecHtmlx TubaUtilsParamSpecHtmlx;

struct _TubaUtilsHtmlx {
	GTypeInstance parent_instance;
	volatile int ref_count;
	TubaUtilsHtmlxPrivate * priv;
};

struct _TubaUtilsHtmlxClass {
	GTypeClass parent_class;
	void (*finalize) (TubaUtilsHtmlx *self);
};

struct _TubaUtilsParamSpecHtmlx {
	GParamSpec parent_instance;
};

static gpointer tuba_utils_htmlx_parent_class = NULL;

VALA_EXTERN gpointer tuba_utils_htmlx_ref (gpointer instance);
VALA_EXTERN void tuba_utils_htmlx_unref (gpointer instance);
VALA_EXTERN GParamSpec* tuba_utils_param_spec_htmlx (const gchar* name,
                                         const gchar* nick,
                                         const gchar* blurb,
                                         GType object_type,
                                         GParamFlags flags);
VALA_EXTERN void tuba_utils_value_set_htmlx (GValue* value,
                                 gpointer v_object);
VALA_EXTERN void tuba_utils_value_take_htmlx (GValue* value,
                                  gpointer v_object);
VALA_EXTERN gpointer tuba_utils_value_get_htmlx (const GValue* value);
VALA_EXTERN GType tuba_utils_htmlx_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TubaUtilsHtmlx, tuba_utils_htmlx_unref)
VALA_EXTERN gchar* tuba_utils_htmlx_remove_tags (const gchar* content);
VALA_EXTERN gchar* tuba_utils_htmlx_replace_with_pango_markup (const gchar* str);
static void tuba_utils_htmlx_remove_tags_handler (xmlNode* root,
                                           gchar** content);
VALA_EXTERN gchar* tuba_utils_htmlx_restore_entities (const gchar* content);
VALA_EXTERN gchar* tuba_utils_htmlx_simplify (const gchar* str);
static void tuba_utils_htmlx_simplify_handler (xmlNode* root,
                                        gchar** content);
VALA_EXTERN gchar* tuba_utils_htmlx_uri_encode (const gchar* str);
VALA_EXTERN gchar* tuba_utils_htmlx_escape_entities (const gchar* content);
VALA_EXTERN TubaUtilsHtmlx* tuba_utils_htmlx_new (void);
VALA_EXTERN TubaUtilsHtmlx* tuba_utils_htmlx_construct (GType object_type);
static void tuba_utils_htmlx_finalize (TubaUtilsHtmlx * obj);
static GType tuba_utils_htmlx_get_type_once (void);

gchar*
tuba_utils_htmlx_remove_tags (const gchar* content)
{
	gchar* fixed_paragraphs = NULL;
	gchar* _tmp0_;
	gchar* to_parse = NULL;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* result;
	g_return_val_if_fail (content != NULL, NULL);
	_tmp0_ = g_strdup (content);
	fixed_paragraphs = _tmp0_;
	_tmp1_ = tuba_utils_htmlx_replace_with_pango_markup (content);
	to_parse = _tmp1_;
	_tmp2_ = to_parse;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		xmlDoc* doc = NULL;
		const gchar* _tmp3_;
		xmlDoc* _tmp4_;
		xmlDoc* _tmp5_;
		xmlDoc* _tmp15_;
		_tmp3_ = to_parse;
		_tmp4_ = htmlReadDoc ((xmlChar*) _tmp3_, "", "utf8", 0);
		doc = _tmp4_;
		_tmp5_ = doc;
		if (_tmp5_ != NULL) {
			xmlNode* root = NULL;
			xmlDoc* _tmp6_;
			xmlNode* _tmp7_;
			xmlNode* _tmp8_;
			_tmp6_ = doc;
			_tmp7_ = xmlDocGetRootElement (_tmp6_);
			root = _tmp7_;
			_tmp8_ = root;
			if (_tmp8_ != NULL) {
				gchar* t_content = NULL;
				const gchar* _tmp9_;
				gchar* _tmp10_;
				xmlNode* _tmp11_;
				gchar* _tmp12_ = NULL;
				const gchar* _tmp13_;
				gchar* _tmp14_;
				_tmp9_ = fixed_paragraphs;
				_tmp10_ = g_strdup (_tmp9_);
				t_content = _tmp10_;
				_tmp11_ = root;
				tuba_utils_htmlx_remove_tags_handler (_tmp11_, &_tmp12_);
				_g_free0 (t_content);
				t_content = _tmp12_;
				_tmp13_ = t_content;
				_tmp14_ = g_strdup (_tmp13_);
				_g_free0 (fixed_paragraphs);
				fixed_paragraphs = _tmp14_;
				_g_free0 (t_content);
			}
		}
		_tmp15_ = doc;
		_xmlFreeDoc0 (_tmp15_);
	}
	_tmp16_ = fixed_paragraphs;
	_tmp17_ = tuba_utils_htmlx_restore_entities (_tmp16_);
	result = _tmp17_;
	_g_free0 (to_parse);
	_g_free0 (fixed_paragraphs);
	return result;
}

static void
tuba_utils_htmlx_remove_tags_handler (xmlNode* root,
                                      gchar** content)
{
	gchar* _vala_content = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GQuark _tmp4_ = 0U;
	static GQuark _tmp3_label0 = 0;
	static GQuark _tmp3_label1 = 0;
	_tmp0_ = g_strdup ("");
	_g_free0 (_vala_content);
	_vala_content = _tmp0_;
	_tmp1_ = root->name;
	_tmp2_ = _tmp1_;
	_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
	if (_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("br")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp5_;
				gchar* _tmp6_;
				_tmp5_ = _vala_content;
				_tmp6_ = g_strconcat (_tmp5_, "\n", NULL);
				_g_free0 (_vala_content);
				_vala_content = _tmp6_;
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("text")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp7_;
				_tmp7_ = root->content;
				if (_tmp7_ != NULL) {
					const gchar* _tmp8_;
					const gchar* _tmp9_;
					gchar* _tmp10_;
					gchar* _tmp11_;
					gchar* _tmp12_;
					_tmp8_ = _vala_content;
					_tmp9_ = root->content;
					_tmp10_ = g_markup_escape_text (_tmp9_, (gssize) -1);
					_tmp11_ = _tmp10_;
					_tmp12_ = g_strconcat (_tmp8_, _tmp11_, NULL);
					_g_free0 (_vala_content);
					_vala_content = _tmp12_;
					_g_free0 (_tmp11_);
				}
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				const gchar* _tmp24_;
				{
					xmlNode* iter = NULL;
					xmlNode* _tmp13_;
					_tmp13_ = root->children;
					iter = _tmp13_;
					{
						gboolean _tmp14_ = FALSE;
						_tmp14_ = TRUE;
						while (TRUE) {
							xmlNode* _tmp17_;
							gchar* t_content = NULL;
							gchar* _tmp18_;
							xmlNode* _tmp19_;
							gchar* _tmp20_ = NULL;
							const gchar* _tmp21_;
							const gchar* _tmp22_;
							gchar* _tmp23_;
							if (!_tmp14_) {
								xmlNode* _tmp15_;
								xmlNode* _tmp16_;
								_tmp15_ = iter;
								_tmp16_ = _tmp15_->next;
								iter = _tmp16_;
							}
							_tmp14_ = FALSE;
							_tmp17_ = iter;
							if (!(_tmp17_ != NULL)) {
								break;
							}
							_tmp18_ = g_strdup ("");
							t_content = _tmp18_;
							_tmp19_ = iter;
							tuba_utils_htmlx_remove_tags_handler (_tmp19_, &_tmp20_);
							_g_free0 (t_content);
							t_content = _tmp20_;
							_tmp21_ = _vala_content;
							_tmp22_ = t_content;
							_tmp23_ = g_strconcat (_tmp21_, _tmp22_, NULL);
							_g_free0 (_vala_content);
							_vala_content = _tmp23_;
							_g_free0 (t_content);
						}
					}
				}
				_tmp24_ = root->name;
				if (g_strcmp0 (_tmp24_, "p") == 0) {
					const gchar* _tmp25_;
					gchar* _tmp26_;
					_tmp25_ = _vala_content;
					_tmp26_ = g_strconcat (_tmp25_, "\n", NULL);
					_g_free0 (_vala_content);
					_vala_content = _tmp26_;
				}
				break;
			}
		}
	}
	if (content) {
		*content = _vala_content;
	} else {
		_g_free0 (_vala_content);
	}
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

gchar*
tuba_utils_htmlx_simplify (const gchar* str)
{
	gchar* simplified = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* result;
	g_return_val_if_fail (str != NULL, NULL);
	_tmp0_ = g_strdup (str);
	simplified = _tmp0_;
	_tmp1_ = simplified;
	if (g_strcmp0 (_tmp1_, "") != 0) {
		xmlDoc* doc = NULL;
		xmlDoc* _tmp2_;
		xmlDoc* _tmp3_;
		xmlDoc* _tmp13_;
		_tmp2_ = htmlReadDoc ((xmlChar*) str, "", "utf8", 0);
		doc = _tmp2_;
		_tmp3_ = doc;
		if (_tmp3_ != NULL) {
			xmlNode* root = NULL;
			xmlDoc* _tmp4_;
			xmlNode* _tmp5_;
			xmlNode* _tmp6_;
			_tmp4_ = doc;
			_tmp5_ = xmlDocGetRootElement (_tmp4_);
			root = _tmp5_;
			_tmp6_ = root;
			if (_tmp6_ != NULL) {
				gchar* t_content = NULL;
				const gchar* _tmp7_;
				gchar* _tmp8_;
				xmlNode* _tmp9_;
				gchar* _tmp10_ = NULL;
				const gchar* _tmp11_;
				gchar* _tmp12_;
				_tmp7_ = simplified;
				_tmp8_ = g_strdup (_tmp7_);
				t_content = _tmp8_;
				_tmp9_ = root;
				tuba_utils_htmlx_simplify_handler (_tmp9_, &_tmp10_);
				_g_free0 (t_content);
				t_content = _tmp10_;
				_tmp11_ = t_content;
				_tmp12_ = g_strdup (_tmp11_);
				_g_free0 (simplified);
				simplified = _tmp12_;
				_g_free0 (t_content);
			}
		}
		_tmp13_ = doc;
		_xmlFreeDoc0 (_tmp13_);
	}
	_tmp14_ = simplified;
	_tmp15_ = string_strip (_tmp14_);
	result = _tmp15_;
	_g_free0 (simplified);
	return result;
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
tuba_utils_htmlx_simplify_handler (xmlNode* root,
                                   gchar** content)
{
	gchar* _vala_content = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GQuark _tmp4_ = 0U;
	static GQuark _tmp3_label0 = 0;
	static GQuark _tmp3_label1 = 0;
	static GQuark _tmp3_label2 = 0;
	_tmp0_ = g_strdup ("");
	_g_free0 (_vala_content);
	_vala_content = _tmp0_;
	_tmp1_ = root->name;
	_tmp2_ = _tmp1_;
	_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
	if (_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("a")))) {
		switch (0) {
			default:
			{
				gchar* href = NULL;
				gchar* _tmp5_;
				const gchar* _tmp6_;
				_tmp5_ = (gchar*) xmlGetProp (root, (xmlChar*) "href");
				href = _tmp5_;
				_tmp6_ = href;
				if (_tmp6_ != NULL) {
					const gchar* _tmp7_;
					const gchar* _tmp8_;
					gchar* _tmp9_;
					gchar* _tmp10_;
					const gchar* _tmp11_;
					gchar* _tmp12_;
					gchar* _tmp13_;
					gchar* _tmp14_;
					const gchar* _tmp26_;
					gchar* _tmp27_;
					_tmp7_ = _vala_content;
					_tmp8_ = href;
					_tmp9_ = g_markup_escape_text (_tmp8_, (gssize) -1);
					_tmp10_ = _tmp9_;
					_tmp11_ = string_to_string (_tmp10_);
					_tmp12_ = g_strconcat ("<a href='", _tmp11_, "'>", NULL);
					_tmp13_ = _tmp12_;
					_tmp14_ = g_strconcat (_tmp7_, _tmp13_, NULL);
					_g_free0 (_vala_content);
					_vala_content = _tmp14_;
					_g_free0 (_tmp13_);
					_g_free0 (_tmp10_);
					{
						xmlNode* iter = NULL;
						xmlNode* _tmp15_;
						_tmp15_ = root->children;
						iter = _tmp15_;
						{
							gboolean _tmp16_ = FALSE;
							_tmp16_ = TRUE;
							while (TRUE) {
								xmlNode* _tmp19_;
								gchar* t_content = NULL;
								gchar* _tmp20_;
								xmlNode* _tmp21_;
								gchar* _tmp22_ = NULL;
								const gchar* _tmp23_;
								const gchar* _tmp24_;
								gchar* _tmp25_;
								if (!_tmp16_) {
									xmlNode* _tmp17_;
									xmlNode* _tmp18_;
									_tmp17_ = iter;
									_tmp18_ = _tmp17_->next;
									iter = _tmp18_;
								}
								_tmp16_ = FALSE;
								_tmp19_ = iter;
								if (!(_tmp19_ != NULL)) {
									break;
								}
								_tmp20_ = g_strdup ("");
								t_content = _tmp20_;
								_tmp21_ = iter;
								tuba_utils_htmlx_simplify_handler (_tmp21_, &_tmp22_);
								_g_free0 (t_content);
								t_content = _tmp22_;
								_tmp23_ = _vala_content;
								_tmp24_ = t_content;
								_tmp25_ = g_strconcat (_tmp23_, _tmp24_, NULL);
								_g_free0 (_vala_content);
								_vala_content = _tmp25_;
								_g_free0 (t_content);
							}
						}
					}
					_tmp26_ = _vala_content;
					_tmp27_ = g_strconcat (_tmp26_, "</a>", NULL);
					_g_free0 (_vala_content);
					_vala_content = _tmp27_;
				}
				_g_free0 (href);
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("br")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp28_;
				gchar* _tmp29_;
				_tmp28_ = _vala_content;
				_tmp29_ = g_strconcat (_tmp28_, "\n", NULL);
				_g_free0 (_vala_content);
				_vala_content = _tmp29_;
				break;
			}
		}
	} else if (_tmp4_ == ((0 != _tmp3_label2) ? _tmp3_label2 : (_tmp3_label2 = g_quark_from_static_string ("text")))) {
		switch (0) {
			default:
			{
				const gchar* _tmp30_;
				_tmp30_ = root->content;
				if (_tmp30_ != NULL) {
					const gchar* _tmp31_;
					const gchar* _tmp32_;
					gchar* _tmp33_;
					gchar* _tmp34_;
					gchar* _tmp35_;
					_tmp31_ = _vala_content;
					_tmp32_ = root->content;
					_tmp33_ = g_markup_escape_text (_tmp32_, (gssize) -1);
					_tmp34_ = _tmp33_;
					_tmp35_ = g_strconcat (_tmp31_, _tmp34_, NULL);
					_g_free0 (_vala_content);
					_vala_content = _tmp35_;
					_g_free0 (_tmp34_);
				}
				break;
			}
		}
	} else {
		switch (0) {
			default:
			{
				const gchar* _tmp47_;
				{
					xmlNode* iter = NULL;
					xmlNode* _tmp36_;
					_tmp36_ = root->children;
					iter = _tmp36_;
					{
						gboolean _tmp37_ = FALSE;
						_tmp37_ = TRUE;
						while (TRUE) {
							xmlNode* _tmp40_;
							gchar* t_content = NULL;
							gchar* _tmp41_;
							xmlNode* _tmp42_;
							gchar* _tmp43_ = NULL;
							const gchar* _tmp44_;
							const gchar* _tmp45_;
							gchar* _tmp46_;
							if (!_tmp37_) {
								xmlNode* _tmp38_;
								xmlNode* _tmp39_;
								_tmp38_ = iter;
								_tmp39_ = _tmp38_->next;
								iter = _tmp39_;
							}
							_tmp37_ = FALSE;
							_tmp40_ = iter;
							if (!(_tmp40_ != NULL)) {
								break;
							}
							_tmp41_ = g_strdup ("");
							t_content = _tmp41_;
							_tmp42_ = iter;
							tuba_utils_htmlx_simplify_handler (_tmp42_, &_tmp43_);
							_g_free0 (t_content);
							t_content = _tmp43_;
							_tmp44_ = _vala_content;
							_tmp45_ = t_content;
							_tmp46_ = g_strconcat (_tmp44_, _tmp45_, NULL);
							_g_free0 (_vala_content);
							_vala_content = _tmp46_;
							_g_free0 (t_content);
						}
					}
				}
				_tmp47_ = root->name;
				if (g_strcmp0 (_tmp47_, "p") == 0) {
					const gchar* _tmp48_;
					gchar* _tmp49_;
					_tmp48_ = _vala_content;
					_tmp49_ = g_strconcat (_tmp48_, "\n\n", NULL);
					_g_free0 (_vala_content);
					_vala_content = _tmp49_;
				}
				break;
			}
		}
	}
	if (content) {
		*content = _vala_content;
	} else {
		_g_free0 (_vala_content);
	}
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	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;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

gchar*
tuba_utils_htmlx_replace_with_pango_markup (const gchar* str)
{
	gchar* res = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* result;
	g_return_val_if_fail (str != NULL, NULL);
	_tmp0_ = string_replace (str, "<strong>", "<b>");
	_tmp1_ = _tmp0_;
	_tmp2_ = string_replace (_tmp1_, "</strong>", "</b>");
	_tmp3_ = _tmp2_;
	_tmp4_ = string_replace (_tmp3_, "<em>", "<i>");
	_tmp5_ = _tmp4_;
	_tmp6_ = string_replace (_tmp5_, "</em>", "</i>");
	_tmp7_ = _tmp6_;
	_tmp8_ = string_replace (_tmp7_, "<del>", "<s>");
	_tmp9_ = _tmp8_;
	_tmp10_ = string_replace (_tmp9_, "</del>", "</s>");
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	res = _tmp11_;
	if (string_contains (str, "<br")) {
		const gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp12_ = res;
		_tmp13_ = string_replace (_tmp12_, "\n", "");
		_g_free0 (res);
		res = _tmp13_;
	}
	result = res;
	return result;
}

gchar*
tuba_utils_htmlx_uri_encode (const gchar* str)
{
	gchar* restored = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (str != NULL, NULL);
	_tmp0_ = tuba_utils_htmlx_restore_entities (str);
	restored = _tmp0_;
	_tmp1_ = g_uri_escape_string (restored, NULL, TRUE);
	result = _tmp1_;
	_g_free0 (restored);
	return result;
}

gchar*
tuba_utils_htmlx_restore_entities (const gchar* content)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* result;
	g_return_val_if_fail (content != NULL, NULL);
	_tmp0_ = string_replace (content, "&lt;", "<");
	_tmp1_ = _tmp0_;
	_tmp2_ = string_replace (_tmp1_, "&gt;", ">");
	_tmp3_ = _tmp2_;
	_tmp4_ = string_replace (_tmp3_, "&apos;", "'");
	_tmp5_ = _tmp4_;
	_tmp6_ = string_replace (_tmp5_, "&quot;", "\"");
	_tmp7_ = _tmp6_;
	_tmp8_ = string_replace (_tmp7_, "&#39;", "'");
	_tmp9_ = _tmp8_;
	_tmp10_ = string_replace (_tmp9_, "&amp;", "&");
	_tmp11_ = _tmp10_;
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp11_;
	return result;
}

gchar*
tuba_utils_htmlx_escape_entities (const gchar* content)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (content != NULL, NULL);
	_tmp0_ = string_replace (content, "&nbsp;", " ");
	_tmp1_ = _tmp0_;
	_tmp2_ = string_replace (_tmp1_, "'", "&apos;");
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	result = _tmp3_;
	return result;
}

TubaUtilsHtmlx*
tuba_utils_htmlx_construct (GType object_type)
{
	TubaUtilsHtmlx* self = NULL;
	self = (TubaUtilsHtmlx*) g_type_create_instance (object_type);
	return self;
}

TubaUtilsHtmlx*
tuba_utils_htmlx_new (void)
{
	return tuba_utils_htmlx_construct (TUBA_UTILS_TYPE_HTMLX);
}

static void
tuba_utils_value_htmlx_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
tuba_utils_value_htmlx_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		tuba_utils_htmlx_unref (value->data[0].v_pointer);
	}
}

static void
tuba_utils_value_htmlx_copy_value (const GValue* src_value,
                                   GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = tuba_utils_htmlx_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
tuba_utils_value_htmlx_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
tuba_utils_value_htmlx_collect_value (GValue* value,
                                      guint n_collect_values,
                                      GTypeCValue* collect_values,
                                      guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		TubaUtilsHtmlx * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = tuba_utils_htmlx_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
tuba_utils_value_htmlx_lcopy_value (const GValue* value,
                                    guint n_collect_values,
                                    GTypeCValue* collect_values,
                                    guint collect_flags)
{
	TubaUtilsHtmlx ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = tuba_utils_htmlx_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
tuba_utils_param_spec_htmlx (const gchar* name,
                             const gchar* nick,
                             const gchar* blurb,
                             GType object_type,
                             GParamFlags flags)
{
	TubaUtilsParamSpecHtmlx* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TUBA_UTILS_TYPE_HTMLX), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
tuba_utils_value_get_htmlx (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TUBA_UTILS_TYPE_HTMLX), NULL);
	return value->data[0].v_pointer;
}

void
tuba_utils_value_set_htmlx (GValue* value,
                            gpointer v_object)
{
	TubaUtilsHtmlx * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TUBA_UTILS_TYPE_HTMLX));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TUBA_UTILS_TYPE_HTMLX));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		tuba_utils_htmlx_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		tuba_utils_htmlx_unref (old);
	}
}

void
tuba_utils_value_take_htmlx (GValue* value,
                             gpointer v_object)
{
	TubaUtilsHtmlx * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TUBA_UTILS_TYPE_HTMLX));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TUBA_UTILS_TYPE_HTMLX));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		tuba_utils_htmlx_unref (old);
	}
}

static void
tuba_utils_htmlx_class_init (TubaUtilsHtmlxClass * klass,
                             gpointer klass_data)
{
	tuba_utils_htmlx_parent_class = g_type_class_peek_parent (klass);
	((TubaUtilsHtmlxClass *) klass)->finalize = tuba_utils_htmlx_finalize;
}

static void
tuba_utils_htmlx_instance_init (TubaUtilsHtmlx * self,
                                gpointer klass)
{
	self->ref_count = 1;
}

static void
tuba_utils_htmlx_finalize (TubaUtilsHtmlx * obj)
{
	TubaUtilsHtmlx * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TUBA_UTILS_TYPE_HTMLX, TubaUtilsHtmlx);
	g_signal_handlers_destroy (self);
}

 G_GNUC_NO_INLINE static GType
tuba_utils_htmlx_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { tuba_utils_value_htmlx_init, tuba_utils_value_htmlx_free_value, tuba_utils_value_htmlx_copy_value, tuba_utils_value_htmlx_peek_pointer, "p", tuba_utils_value_htmlx_collect_value, "p", tuba_utils_value_htmlx_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (TubaUtilsHtmlxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tuba_utils_htmlx_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TubaUtilsHtmlx), 0, (GInstanceInitFunc) tuba_utils_htmlx_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType tuba_utils_htmlx_type_id;
	tuba_utils_htmlx_type_id = g_type_register_fundamental (g_type_fundamental_next (), "TubaUtilsHtmlx", &g_define_type_info, &g_define_type_fundamental_info, G_TYPE_FLAG_NONE);
	return tuba_utils_htmlx_type_id;
}

GType
tuba_utils_htmlx_get_type (void)
{
	static GType tuba_utils_htmlx_type_id__once = 0;
	if (g_once_init_enter_pointer (&tuba_utils_htmlx_type_id__once)) {
		GType tuba_utils_htmlx_type_id;
		tuba_utils_htmlx_type_id = tuba_utils_htmlx_get_type_once ();
		g_once_init_leave_pointer (&tuba_utils_htmlx_type_id__once, tuba_utils_htmlx_type_id);
	}
	return tuba_utils_htmlx_type_id__once;
}

gpointer
tuba_utils_htmlx_ref (gpointer instance)
{
	TubaUtilsHtmlx * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
tuba_utils_htmlx_unref (gpointer instance)
{
	TubaUtilsHtmlx * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		TUBA_UTILS_HTMLX_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

