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

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "libkkc/libkkc.h"

#define KKC_ENCODING_CONVERTER_BUFSIZ 4096
#define KKC_ENCODING_CONVERTER_INTERNAL_ENCODING "UTF-8"
#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

#define KKC_TYPE_ENCODING_CONVERTER (kkc_encoding_converter_get_type ())
#define KKC_ENCODING_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_ENCODING_CONVERTER, KkcEncodingConverter))
#define KKC_ENCODING_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_ENCODING_CONVERTER, KkcEncodingConverterClass))
#define KKC_IS_ENCODING_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_ENCODING_CONVERTER))
#define KKC_IS_ENCODING_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_ENCODING_CONVERTER))
#define KKC_ENCODING_CONVERTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_ENCODING_CONVERTER, KkcEncodingConverterClass))

typedef struct _KkcEncodingConverter KkcEncodingConverter;
typedef struct _KkcEncodingConverterClass KkcEncodingConverterClass;
typedef struct _KkcEncodingConverterPrivate KkcEncodingConverterPrivate;
enum  {
	KKC_ENCODING_CONVERTER_0_PROPERTY,
	KKC_ENCODING_CONVERTER_ENCODING_PROPERTY,
	KKC_ENCODING_CONVERTER_NUM_PROPERTIES
};
static GParamSpec* kkc_encoding_converter_properties[KKC_ENCODING_CONVERTER_NUM_PROPERTIES];

#define KKC_ENCODING_CONVERTER_TYPE_ENCODING_CODING_SYSTEM_ENTRY (kkc_encoding_converter_encoding_coding_system_entry_get_type ())
typedef struct _KkcEncodingConverterEncodingCodingSystemEntry KkcEncodingConverterEncodingCodingSystemEntry;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_match_info_unref0(var) ((var == NULL) ? NULL : (var = (g_match_info_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

struct _KkcEncodingConverter {
	GObject parent_instance;
	KkcEncodingConverterPrivate * priv;
};

struct _KkcEncodingConverterClass {
	GObjectClass parent_class;
};

struct _KkcEncodingConverterPrivate {
	gchar* _encoding;
	GCharsetConverter* encoder;
	GCharsetConverter* decoder;
};

struct _KkcEncodingConverterEncodingCodingSystemEntry {
	gchar* key;
	gchar* value;
};

static gint KkcEncodingConverter_private_offset;
static gpointer kkc_encoding_converter_parent_class = NULL;
static GRegex* kkc_encoding_converter_coding_cookie_regex;
static GRegex* kkc_encoding_converter_coding_cookie_regex = NULL;
static GInitableIface * kkc_encoding_converter_g_initable_parent_iface = NULL;

VALA_EXTERN GType kkc_encoding_converter_get_type (void) G_GNUC_CONST ;
static GType kkc_encoding_converter_encoding_coding_system_entry_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static KkcEncodingConverterEncodingCodingSystemEntry* kkc_encoding_converter_encoding_coding_system_entry_dup (const KkcEncodingConverterEncodingCodingSystemEntry* self);
static void kkc_encoding_converter_encoding_coding_system_entry_free (KkcEncodingConverterEncodingCodingSystemEntry* self);
static void kkc_encoding_converter_encoding_coding_system_entry_copy (const KkcEncodingConverterEncodingCodingSystemEntry* self,
                                                               KkcEncodingConverterEncodingCodingSystemEntry* dest);
static void kkc_encoding_converter_encoding_coding_system_entry_destroy (KkcEncodingConverterEncodingCodingSystemEntry* self);
VALA_EXTERN gchar* kkc_encoding_converter_extract_coding_system (const gchar* line);
static gboolean kkc_encoding_converter_real_init (GInitable* base,
                                           GCancellable* cancellable,
                                           GError** error);
VALA_EXTERN const gchar* kkc_encoding_converter_get_encoding (KkcEncodingConverter* self);
VALA_EXTERN KkcEncodingConverter* kkc_encoding_converter_new (const gchar* encoding,
                                                  GError** error);
VALA_EXTERN KkcEncodingConverter* kkc_encoding_converter_construct (GType object_type,
                                                        const gchar* encoding,
                                                        GError** error);
VALA_EXTERN KkcEncodingConverter* kkc_encoding_converter_new_from_coding_system (const gchar* coding,
                                                                     GError** error);
VALA_EXTERN KkcEncodingConverter* kkc_encoding_converter_construct_from_coding_system (GType object_type,
                                                                           const gchar* coding,
                                                                           GError** error);
static gchar* kkc_encoding_converter_convert (KkcEncodingConverter* self,
                                       GCharsetConverter* converter,
                                       const gchar* str,
                                       GError** error);
static guint8* _vala_array_dup5 (guint8* self,
                          gssize length);
VALA_EXTERN gchar* kkc_encoding_converter_encode (KkcEncodingConverter* self,
                                      const gchar* internal_str,
                                      GError** error);
VALA_EXTERN gchar* kkc_encoding_converter_decode (KkcEncodingConverter* self,
                                      const gchar* external_str,
                                      GError** error);
VALA_EXTERN void kkc_encoding_converter_set_encoding (KkcEncodingConverter* self,
                                          const gchar* value);
static void kkc_encoding_converter_finalize (GObject * obj);
static GType kkc_encoding_converter_get_type_once (void);
static void _vala_kkc_encoding_converter_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_kkc_encoding_converter_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const KkcEncodingConverterEncodingCodingSystemEntry KKC_ENCODING_CONVERTER_ENCODING_TO_CODING_SYSTEM_RULE[7] = {{"UTF-8", "utf-8"}, {"EUC-JP", "euc-jp"}, {"Shift_JIS", "shift_jis"}, {"ISO-2022-JP", "iso-2022-jp"}, {"EUC-JISX0213", "euc-jisx0213"}, {"EUC-JISX0213", "euc-jis-2004"}, {"SHIFT_JISX0213", "shift_jis-2004"}};

static inline gpointer
kkc_encoding_converter_get_instance_private (KkcEncodingConverter* self)
{
	return G_STRUCT_MEMBER_P (self, KkcEncodingConverter_private_offset);
}

gchar*
kkc_encoding_converter_extract_coding_system (const gchar* line)
{
	GMatchInfo* info = NULL;
	GRegex* _tmp0_;
	GMatchInfo* _tmp1_ = NULL;
	gboolean _tmp2_;
	gchar* result;
	g_return_val_if_fail (line != NULL, NULL);
	info = NULL;
	_tmp0_ = kkc_encoding_converter_coding_cookie_regex;
	_tmp2_ = g_regex_match (_tmp0_, line, 0, &_tmp1_);
	_g_match_info_unref0 (info);
	info = _tmp1_;
	if (_tmp2_) {
		GMatchInfo* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = info;
		_tmp4_ = g_match_info_fetch (_tmp3_, 1);
		result = _tmp4_;
		_g_match_info_unref0 (info);
		return result;
	}
	result = NULL;
	_g_match_info_unref0 (info);
	return result;
}

static gboolean
kkc_encoding_converter_real_init (GInitable* base,
                                  GCancellable* cancellable,
                                  GError** error)
{
	KkcEncodingConverter * self;
	GCharsetConverter* _tmp0_ = NULL;
	const gchar* _tmp1_;
	GCharsetConverter* _tmp2_;
	GCharsetConverter* _tmp4_;
	GCharsetConverter* _tmp5_ = NULL;
	const gchar* _tmp6_;
	GCharsetConverter* _tmp7_;
	GCharsetConverter* _tmp9_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (KkcEncodingConverter*) base;
	_tmp1_ = self->priv->_encoding;
	_tmp2_ = g_charset_converter_new (_tmp1_, KKC_ENCODING_CONVERTER_INTERNAL_ENCODING, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp3_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp3_;
	}
	_tmp4_ = _tmp0_;
	_tmp0_ = NULL;
	_g_object_unref0 (self->priv->encoder);
	self->priv->encoder = _tmp4_;
	_tmp6_ = self->priv->_encoding;
	_tmp7_ = g_charset_converter_new (KKC_ENCODING_CONVERTER_INTERNAL_ENCODING, _tmp6_, &_inner_error0_);
	_tmp5_ = _tmp7_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp8_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp0_);
		return _tmp8_;
	}
	_tmp9_ = _tmp5_;
	_tmp5_ = NULL;
	_g_object_unref0 (self->priv->decoder);
	self->priv->decoder = _tmp9_;
	result = TRUE;
	_g_object_unref0 (_tmp5_);
	_g_object_unref0 (_tmp0_);
	return result;
}

KkcEncodingConverter*
kkc_encoding_converter_construct (GType object_type,
                                  const gchar* encoding,
                                  GError** error)
{
	KkcEncodingConverter * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (encoding != NULL, NULL);
	self = (KkcEncodingConverter*) g_object_new (object_type, "encoding", encoding, NULL);
	g_initable_init ((GInitable*) self, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (self);
		return NULL;
	}
	return self;
}

KkcEncodingConverter*
kkc_encoding_converter_new (const gchar* encoding,
                            GError** error)
{
	return kkc_encoding_converter_construct (KKC_TYPE_ENCODING_CONVERTER, encoding, error);
}

KkcEncodingConverter*
kkc_encoding_converter_construct_from_coding_system (GType object_type,
                                                     const gchar* coding,
                                                     GError** error)
{
	KkcEncodingConverter * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (coding != NULL, NULL);
	{
		KkcEncodingConverterEncodingCodingSystemEntry* entry_collection = NULL;
		gint entry_collection_length1 = 0;
		gint _entry_collection_size_ = 0;
		gint entry_it = 0;
		entry_collection = KKC_ENCODING_CONVERTER_ENCODING_TO_CODING_SYSTEM_RULE;
		entry_collection_length1 = G_N_ELEMENTS (KKC_ENCODING_CONVERTER_ENCODING_TO_CODING_SYSTEM_RULE);
		for (entry_it = 0; entry_it < entry_collection_length1; entry_it = entry_it + 1) {
			KkcEncodingConverterEncodingCodingSystemEntry entry = {0};
			entry = entry_collection[entry_it];
			{
				KkcEncodingConverterEncodingCodingSystemEntry _tmp0_;
				const gchar* _tmp1_;
				_tmp0_ = entry;
				_tmp1_ = _tmp0_.value;
				if (g_strcmp0 (_tmp1_, coding) == 0) {
					KkcEncodingConverterEncodingCodingSystemEntry _tmp2_;
					const gchar* _tmp3_;
					_tmp2_ = entry;
					_tmp3_ = _tmp2_.key;
					self = (KkcEncodingConverter*) kkc_encoding_converter_construct (object_type, _tmp3_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						g_propagate_error (error, _inner_error0_);
						_g_object_unref0 (self);
						return NULL;
					}
					return self;
				}
			}
		}
	}
	g_assert_not_reached ();
	return self;
}

KkcEncodingConverter*
kkc_encoding_converter_new_from_coding_system (const gchar* coding,
                                               GError** error)
{
	return kkc_encoding_converter_construct_from_coding_system (KKC_TYPE_ENCODING_CONVERTER, coding, error);
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static guint8*
_vala_array_dup5 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static gchar*
kkc_encoding_converter_convert (KkcEncodingConverter* self,
                                GCharsetConverter* converter,
                                const gchar* str,
                                GError** error)
{
	guint8* inbuf = NULL;
	guint8* _tmp0_;
	gint _tmp0__length1;
	gint _tmp1_ = 0;
	guint8* _tmp2_;
	gint _tmp2__length1;
	guint8* _tmp3_;
	gint _tmp3__length1;
	gint inbuf_length1;
	gint _inbuf_size_;
	guint8* outbuf = NULL;
	guint8* _tmp4_;
	gint outbuf_length1;
	gint _outbuf_size_;
	GString* builder = NULL;
	GString* _tmp5_;
	gsize total_bytes_read = 0UL;
	GString* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (converter != NULL, NULL);
	g_return_val_if_fail (str != NULL, NULL);
	_tmp0_ = string_get_data (str, &_tmp1_);
	_tmp0__length1 = _tmp1_;
	_tmp2_ = _tmp0_;
	_tmp2__length1 = _tmp0__length1;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup5 (_tmp2_, _tmp2__length1) : _tmp2_;
	_tmp3__length1 = _tmp2__length1;
	inbuf = _tmp3_;
	inbuf_length1 = _tmp3__length1;
	_inbuf_size_ = inbuf_length1;
	_tmp4_ = g_new0 (guint8, KKC_ENCODING_CONVERTER_BUFSIZ);
	outbuf = _tmp4_;
	outbuf_length1 = KKC_ENCODING_CONVERTER_BUFSIZ;
	_outbuf_size_ = outbuf_length1;
	_tmp5_ = g_string_new ("");
	builder = _tmp5_;
	total_bytes_read = (gsize) 0;
	while (TRUE) {
		guint8* _tmp6_;
		gint _tmp6__length1;
		gsize bytes_read = 0UL;
		gsize bytes_written = 0UL;
		guint8* _tmp7_;
		gint _tmp7__length1;
		guint8* _tmp8_;
		gint _tmp8__length1;
		guint8* _tmp9_;
		gint _tmp9__length1;
		gsize _tmp10_ = 0UL;
		gsize _tmp11_ = 0UL;
		_tmp6_ = inbuf;
		_tmp6__length1 = inbuf_length1;
		if (!(total_bytes_read < ((gsize) _tmp6__length1))) {
			break;
		}
		_tmp7_ = inbuf;
		_tmp7__length1 = inbuf_length1;
		_tmp8_ = inbuf;
		_tmp8__length1 = inbuf_length1;
		_tmp9_ = outbuf;
		_tmp9__length1 = outbuf_length1;
		g_converter_convert ((GConverter*) converter, _tmp7_ + ((gint) total_bytes_read), (gsize) (_tmp8__length1 - ((gint) total_bytes_read)), _tmp9_, (gsize) _tmp9__length1, G_CONVERTER_INPUT_AT_END, &_tmp10_, &_tmp11_, &_inner_error0_);
		bytes_read = _tmp10_;
		bytes_written = _tmp11_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_string_free0 (builder);
			outbuf = (g_free (outbuf), NULL);
			inbuf = (g_free (inbuf), NULL);
			return NULL;
		}
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp12_ = FALSE;
				_tmp12_ = TRUE;
				while (TRUE) {
					GString* _tmp14_;
					guint8* _tmp15_;
					gint _tmp15__length1;
					guint8 _tmp16_;
					if (!_tmp12_) {
						gint _tmp13_;
						_tmp13_ = i;
						i = _tmp13_ + 1;
					}
					_tmp12_ = FALSE;
					if (!(((gsize) i) < bytes_written)) {
						break;
					}
					_tmp14_ = builder;
					_tmp15_ = outbuf;
					_tmp15__length1 = outbuf_length1;
					_tmp16_ = _tmp15_[i];
					g_string_append_c (_tmp14_, (gchar) _tmp16_);
				}
			}
		}
		total_bytes_read += bytes_read;
	}
	_tmp17_ = builder;
	_tmp18_ = _tmp17_->str;
	_tmp19_ = g_strdup (_tmp18_);
	result = _tmp19_;
	_g_string_free0 (builder);
	outbuf = (g_free (outbuf), NULL);
	inbuf = (g_free (inbuf), NULL);
	return result;
}

gchar*
kkc_encoding_converter_encode (KkcEncodingConverter* self,
                               const gchar* internal_str,
                               GError** error)
{
	gchar* _tmp0_ = NULL;
	GCharsetConverter* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (internal_str != NULL, NULL);
	_tmp1_ = self->priv->encoder;
	_tmp2_ = kkc_encoding_converter_convert (self, _tmp1_, internal_str, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_free0 (_tmp0_);
	return result;
}

gchar*
kkc_encoding_converter_decode (KkcEncodingConverter* self,
                               const gchar* external_str,
                               GError** error)
{
	gchar* _tmp0_ = NULL;
	GCharsetConverter* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (external_str != NULL, NULL);
	_tmp1_ = self->priv->decoder;
	_tmp2_ = kkc_encoding_converter_convert (self, _tmp1_, external_str, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_free0 (_tmp0_);
	return result;
}

const gchar*
kkc_encoding_converter_get_encoding (KkcEncodingConverter* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_encoding;
	result = _tmp0_;
	return result;
}

void
kkc_encoding_converter_set_encoding (KkcEncodingConverter* self,
                                     const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = kkc_encoding_converter_get_encoding (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_encoding);
		self->priv->_encoding = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, kkc_encoding_converter_properties[KKC_ENCODING_CONVERTER_ENCODING_PROPERTY]);
	}
}

static void
kkc_encoding_converter_encoding_coding_system_entry_copy (const KkcEncodingConverterEncodingCodingSystemEntry* self,
                                                          KkcEncodingConverterEncodingCodingSystemEntry* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = (*self).key;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).key);
	(*dest).key = _tmp1_;
	_tmp2_ = (*self).value;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).value);
	(*dest).value = _tmp3_;
}

static void
kkc_encoding_converter_encoding_coding_system_entry_destroy (KkcEncodingConverterEncodingCodingSystemEntry* self)
{
	_g_free0 ((*self).key);
	_g_free0 ((*self).value);
}

static KkcEncodingConverterEncodingCodingSystemEntry*
kkc_encoding_converter_encoding_coding_system_entry_dup (const KkcEncodingConverterEncodingCodingSystemEntry* self)
{
	KkcEncodingConverterEncodingCodingSystemEntry* dup;
	dup = g_new0 (KkcEncodingConverterEncodingCodingSystemEntry, 1);
	kkc_encoding_converter_encoding_coding_system_entry_copy (self, dup);
	return dup;
}

static void
kkc_encoding_converter_encoding_coding_system_entry_free (KkcEncodingConverterEncodingCodingSystemEntry* self)
{
	kkc_encoding_converter_encoding_coding_system_entry_destroy (self);
	g_free (self);
}

static GType
kkc_encoding_converter_encoding_coding_system_entry_get_type_once (void)
{
	GType kkc_encoding_converter_encoding_coding_system_entry_type_id;
	kkc_encoding_converter_encoding_coding_system_entry_type_id = g_boxed_type_register_static ("KkcEncodingConverterEncodingCodingSystemEntry", (GBoxedCopyFunc) kkc_encoding_converter_encoding_coding_system_entry_dup, (GBoxedFreeFunc) kkc_encoding_converter_encoding_coding_system_entry_free);
	return kkc_encoding_converter_encoding_coding_system_entry_type_id;
}

static GType
kkc_encoding_converter_encoding_coding_system_entry_get_type (void)
{
	static volatile gsize kkc_encoding_converter_encoding_coding_system_entry_type_id__once = 0;
	if (g_once_init_enter (&kkc_encoding_converter_encoding_coding_system_entry_type_id__once)) {
		GType kkc_encoding_converter_encoding_coding_system_entry_type_id;
		kkc_encoding_converter_encoding_coding_system_entry_type_id = kkc_encoding_converter_encoding_coding_system_entry_get_type_once ();
		g_once_init_leave (&kkc_encoding_converter_encoding_coding_system_entry_type_id__once, kkc_encoding_converter_encoding_coding_system_entry_type_id);
	}
	return kkc_encoding_converter_encoding_coding_system_entry_type_id__once;
}

static void
kkc_encoding_converter_class_init (KkcEncodingConverterClass * klass,
                                   gpointer klass_data)
{
	GError* _inner_error0_ = NULL;
	kkc_encoding_converter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcEncodingConverter_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_encoding_converter_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_kkc_encoding_converter_set_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_encoding_converter_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_ENCODING_CONVERTER_ENCODING_PROPERTY, kkc_encoding_converter_properties[KKC_ENCODING_CONVERTER_ENCODING_PROPERTY] = g_param_spec_string ("encoding", "encoding", "encoding", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	{
		GRegex* _tmp0_ = NULL;
		GRegex* _tmp1_;
		GRegex* _tmp2_;
		_tmp1_ = g_regex_new ("-\\*-.*[ \t]coding:[ \t]*([^ \t;]+?)[ \t;].*-\\*-", 0, 0, &_inner_error0_);
		_tmp0_ = _tmp1_;
		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_);
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_regex_unref0 (kkc_encoding_converter_coding_cookie_regex);
		kkc_encoding_converter_coding_cookie_regex = _tmp2_;
		_g_regex_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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_);
	}
}

static void
kkc_encoding_converter_g_initable_interface_init (GInitableIface * iface,
                                                  gpointer iface_data)
{
	kkc_encoding_converter_g_initable_parent_iface = g_type_interface_peek_parent (iface);
	iface->init = (gboolean (*) (GInitable*, GCancellable*, GError**)) kkc_encoding_converter_real_init;
}

static void
kkc_encoding_converter_instance_init (KkcEncodingConverter * self,
                                      gpointer klass)
{
	self->priv = kkc_encoding_converter_get_instance_private (self);
}

static void
kkc_encoding_converter_finalize (GObject * obj)
{
	KkcEncodingConverter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_ENCODING_CONVERTER, KkcEncodingConverter);
	_g_free0 (self->priv->_encoding);
	_g_object_unref0 (self->priv->encoder);
	_g_object_unref0 (self->priv->decoder);
	G_OBJECT_CLASS (kkc_encoding_converter_parent_class)->finalize (obj);
}

static GType
kkc_encoding_converter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcEncodingConverterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_encoding_converter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcEncodingConverter), 0, (GInstanceInitFunc) kkc_encoding_converter_instance_init, NULL };
	static const GInterfaceInfo g_initable_info = { (GInterfaceInitFunc) kkc_encoding_converter_g_initable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_encoding_converter_type_id;
	kkc_encoding_converter_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcEncodingConverter", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_encoding_converter_type_id, g_initable_get_type (), &g_initable_info);
	KkcEncodingConverter_private_offset = g_type_add_instance_private (kkc_encoding_converter_type_id, sizeof (KkcEncodingConverterPrivate));
	return kkc_encoding_converter_type_id;
}

GType
kkc_encoding_converter_get_type (void)
{
	static volatile gsize kkc_encoding_converter_type_id__once = 0;
	if (g_once_init_enter (&kkc_encoding_converter_type_id__once)) {
		GType kkc_encoding_converter_type_id;
		kkc_encoding_converter_type_id = kkc_encoding_converter_get_type_once ();
		g_once_init_leave (&kkc_encoding_converter_type_id__once, kkc_encoding_converter_type_id);
	}
	return kkc_encoding_converter_type_id__once;
}

static void
_vala_kkc_encoding_converter_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	KkcEncodingConverter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_ENCODING_CONVERTER, KkcEncodingConverter);
	switch (property_id) {
		case KKC_ENCODING_CONVERTER_ENCODING_PROPERTY:
		g_value_set_string (value, kkc_encoding_converter_get_encoding (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_kkc_encoding_converter_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	KkcEncodingConverter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_ENCODING_CONVERTER, KkcEncodingConverter);
	switch (property_id) {
		case KKC_ENCODING_CONVERTER_ENCODING_PROPERTY:
		kkc_encoding_converter_set_encoding (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

