/* numeric-template.c generated by valac 0.56.19, the Vala compiler
 * generated from numeric-template.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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include "libkkc/libkkc.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

#define KKC_TYPE_TEMPLATE (kkc_template_get_type ())
#define KKC_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_TEMPLATE, KkcTemplate))
#define KKC_IS_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_TEMPLATE))
#define KKC_TEMPLATE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), KKC_TYPE_TEMPLATE, KkcTemplateIface))

typedef struct _KkcTemplate KkcTemplate;
typedef struct _KkcTemplateIface KkcTemplateIface;

#define KKC_TYPE_NUMERIC_TEMPLATE (kkc_numeric_template_get_type ())
#define KKC_NUMERIC_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplate))
#define KKC_NUMERIC_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplateClass))
#define KKC_IS_NUMERIC_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_NUMERIC_TEMPLATE))
#define KKC_IS_NUMERIC_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_NUMERIC_TEMPLATE))
#define KKC_NUMERIC_TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplateClass))

typedef struct _KkcNumericTemplate KkcNumericTemplate;
typedef struct _KkcNumericTemplateClass KkcNumericTemplateClass;
typedef struct _KkcNumericTemplatePrivate KkcNumericTemplatePrivate;
enum  {
	KKC_NUMERIC_TEMPLATE_0_PROPERTY,
	KKC_NUMERIC_TEMPLATE_SOURCE_PROPERTY,
	KKC_NUMERIC_TEMPLATE_OKURI_PROPERTY,
	KKC_NUMERIC_TEMPLATE_NUM_PROPERTIES
};
static GParamSpec* kkc_numeric_template_properties[KKC_NUMERIC_TEMPLATE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#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_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)))
typedef enum  {
	KKC_NUMERIC_CONVERSION_TYPE_LATIN,
	KKC_NUMERIC_CONVERSION_TYPE_WIDE_LATIN,
	KKC_NUMERIC_CONVERSION_TYPE_KANJI_NUMERAL,
	KKC_NUMERIC_CONVERSION_TYPE_KANJI,
	KKC_NUMERIC_CONVERSION_TYPE_RECONVERT,
	KKC_NUMERIC_CONVERSION_TYPE_DAIJI,
	KKC_NUMERIC_CONVERSION_TYPE_RESERVED6,
	KKC_NUMERIC_CONVERSION_TYPE_RESERVED7,
	KKC_NUMERIC_CONVERSION_TYPE_GROUPING,
	KKC_NUMERIC_CONVERSION_TYPE_SHOGI
} KkcNumericConversionType;

#define KKC_TYPE_NUMERIC_CONVERSION_TYPE (kkc_numeric_conversion_type_get_type ())

struct _KkcTemplateIface {
	GTypeInterface parent_iface;
	gchar* (*expand) (KkcTemplate* self, const gchar* text);
	const gchar* (*get_source) (KkcTemplate* self);
	void (*set_source) (KkcTemplate* self, const gchar* value);
	gboolean (*get_okuri) (KkcTemplate* self);
	void (*set_okuri) (KkcTemplate* self, gboolean value);
};

struct _KkcNumericTemplate {
	GObject parent_instance;
	KkcNumericTemplatePrivate * priv;
};

struct _KkcNumericTemplateClass {
	GObjectClass parent_class;
};

struct _KkcNumericTemplatePrivate {
	GeeArrayList* numerics;
	gchar* _source;
	gboolean _okuri;
	GRegex* regex;
	GRegex* ref_regex;
};

static gint KkcNumericTemplate_private_offset;
static gpointer kkc_numeric_template_parent_class = NULL;
static KkcTemplateIface * kkc_numeric_template_kkc_template_parent_iface = NULL;

VALA_EXTERN GType kkc_template_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType kkc_numeric_template_get_type (void) G_GNUC_CONST ;
VALA_EXTERN KkcNumericTemplate* kkc_numeric_template_new (const gchar* source);
VALA_EXTERN KkcNumericTemplate* kkc_numeric_template_construct (GType object_type,
                                                    const gchar* source);
VALA_EXTERN void kkc_template_set_okuri (KkcTemplate* self,
                             gboolean value);
static void kkc_numeric_template_extract_numerics (KkcNumericTemplate* self,
                                            const gchar* source);
VALA_EXTERN void kkc_template_set_source (KkcTemplate* self,
                              const gchar* value);
static gchar* kkc_numeric_template_real_expand (KkcTemplate* base,
                                         const gchar* text);
VALA_EXTERN const gchar* kkc_template_get_source (KkcTemplate* self);
VALA_EXTERN GType kkc_numeric_conversion_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* kkc_rom_kana_utils_get_numeric (gint numeric,
                                       KkcNumericConversionType type);
VALA_EXTERN gchar* kkc_template_expand (KkcTemplate* self,
                            const gchar* text);
VALA_EXTERN gboolean kkc_template_get_okuri (KkcTemplate* self);
static void kkc_numeric_template_finalize (GObject * obj);
static GType kkc_numeric_template_get_type_once (void);
static void _vala_kkc_numeric_template_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static void _vala_kkc_numeric_template_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
kkc_numeric_template_get_instance_private (KkcNumericTemplate* self)
{
	return G_STRUCT_MEMBER_P (self, KkcNumericTemplate_private_offset);
}

KkcNumericTemplate*
kkc_numeric_template_construct (GType object_type,
                                const gchar* source)
{
	KkcNumericTemplate * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (source != NULL, NULL);
	self = (KkcNumericTemplate*) g_object_new (object_type, NULL);
	{
		GRegex* _tmp0_ = NULL;
		GRegex* _tmp1_;
		GRegex* _tmp2_;
		_tmp1_ = g_regex_new ("[0-9]+", 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_);
			return NULL;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_regex_unref0 (self->priv->regex);
		self->priv->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_);
		return NULL;
	}
	{
		GRegex* _tmp3_ = NULL;
		GRegex* _tmp4_;
		GRegex* _tmp5_;
		_tmp4_ = g_regex_new ("#([0-9])", 0, 0, &_inner_error0_);
		_tmp3_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch1_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;
		}
		_tmp5_ = _tmp3_;
		_tmp3_ = NULL;
		_g_regex_unref0 (self->priv->ref_regex);
		self->priv->ref_regex = _tmp5_;
		_g_regex_unref0 (_tmp3_);
	}
	goto __finally1;
	__catch1_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally1:
	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_);
		return NULL;
	}
	kkc_template_set_okuri ((KkcTemplate*) self, FALSE);
	kkc_numeric_template_extract_numerics (self, source);
	return self;
}

KkcNumericTemplate*
kkc_numeric_template_new (const gchar* source)
{
	return kkc_numeric_template_construct (KKC_TYPE_NUMERIC_TEMPLATE, source);
}

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

static void
kkc_numeric_template_extract_numerics (KkcNumericTemplate* self,
                                       const gchar* source)
{
	GMatchInfo* info = NULL;
	gint start_pos = 0;
	GString* builder = NULL;
	GString* _tmp0_;
	GString* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	GString* _tmp21_;
	const gchar* _tmp22_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	info = NULL;
	start_pos = 0;
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	while (TRUE) {
		gchar* numeric = NULL;
		GMatchInfo* _tmp5_;
		gchar* _tmp6_;
		gint match_start_pos = 0;
		gint match_end_pos = 0;
		GMatchInfo* _tmp7_;
		gint _tmp8_ = 0;
		gint _tmp9_ = 0;
		GeeArrayList* _tmp10_;
		const gchar* _tmp11_;
		GString* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		GString* _tmp15_;
		{
			gboolean _tmp1_ = FALSE;
			GRegex* _tmp2_;
			GMatchInfo* _tmp3_ = NULL;
			gboolean _tmp4_;
			_tmp2_ = self->priv->regex;
			_tmp4_ = g_regex_match_full (_tmp2_, source, (gssize) -1, start_pos, 0, &_tmp3_, &_inner_error0_);
			_g_match_info_unref0 (info);
			info = _tmp3_;
			_tmp1_ = _tmp4_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == G_REGEX_ERROR) {
					goto __catch0_g_regex_error;
				}
				_g_string_free0 (builder);
				_g_match_info_unref0 (info);
				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;
			}
			if (!_tmp1_) {
				break;
			}
		}
		goto __finally0;
		__catch0_g_regex_error:
		{
			g_clear_error (&_inner_error0_);
			g_return_if_reached ();
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_string_free0 (builder);
			_g_match_info_unref0 (info);
			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;
		}
		_tmp5_ = info;
		_tmp6_ = g_match_info_fetch (_tmp5_, 0);
		numeric = _tmp6_;
		_tmp7_ = info;
		g_match_info_fetch_pos (_tmp7_, 0, &_tmp8_, &_tmp9_);
		match_start_pos = _tmp8_;
		match_end_pos = _tmp9_;
		_tmp10_ = self->priv->numerics;
		_tmp11_ = numeric;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, (gpointer) ((gintptr) atoi (_tmp11_)));
		_tmp12_ = builder;
		_tmp13_ = string_slice (source, (glong) start_pos, (glong) match_start_pos);
		_tmp14_ = _tmp13_;
		g_string_append (_tmp12_, _tmp14_);
		_g_free0 (_tmp14_);
		_tmp15_ = builder;
		g_string_append (_tmp15_, "#");
		start_pos = match_end_pos;
		_g_free0 (numeric);
	}
	_tmp16_ = builder;
	_tmp17_ = strlen (source);
	_tmp18_ = _tmp17_;
	_tmp19_ = string_slice (source, (glong) start_pos, (glong) _tmp18_);
	_tmp20_ = _tmp19_;
	g_string_append (_tmp16_, _tmp20_);
	_g_free0 (_tmp20_);
	_tmp21_ = builder;
	_tmp22_ = _tmp21_->str;
	kkc_template_set_source ((KkcTemplate*) self, _tmp22_);
	_g_string_free0 (builder);
	_g_match_info_unref0 (info);
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static gchar*
kkc_numeric_template_real_expand (KkcTemplate* base,
                                  const gchar* text)
{
	KkcNumericTemplate * self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	GString* builder = NULL;
	GString* _tmp10_;
	GMatchInfo* info = NULL;
	gint start_pos = 0;
	GString* _tmp46_;
	gint _tmp47_;
	gint _tmp48_;
	gchar* _tmp49_;
	gchar* _tmp50_;
	GString* _tmp51_;
	const gchar* _tmp52_;
	gchar* _tmp53_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	self = (KkcNumericTemplate*) base;
	g_return_val_if_fail (text != NULL, NULL);
	_tmp2_ = kkc_template_get_source ((KkcTemplate*) self);
	_tmp3_ = _tmp2_;
	if (g_strcmp0 (_tmp3_, "#") == 0) {
		_tmp1_ = g_strcmp0 (text, "＃") == 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		_tmp4_ = self->priv->numerics;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_ > 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GeeArrayList* _tmp7_;
		gpointer _tmp8_;
		gchar* _tmp9_;
		_tmp7_ = self->priv->numerics;
		_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, 0);
		_tmp9_ = kkc_rom_kana_utils_get_numeric ((gint) ((gintptr) _tmp8_), KKC_NUMERIC_CONVERSION_TYPE_LATIN);
		result = _tmp9_;
		return result;
	}
	_tmp10_ = g_string_new ("");
	builder = _tmp10_;
	info = NULL;
	start_pos = 0;
	{
		gint index = 0;
		index = 0;
		{
			gboolean _tmp11_ = FALSE;
			_tmp11_ = TRUE;
			while (TRUE) {
				GeeArrayList* _tmp13_;
				gint _tmp14_;
				gint _tmp15_;
				gint match_start_pos = 0;
				gint match_end_pos = 0;
				GMatchInfo* _tmp20_;
				gint _tmp21_ = 0;
				gint _tmp22_ = 0;
				GString* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				gchar* type = NULL;
				GMatchInfo* _tmp26_;
				gchar* _tmp27_;
				const gchar* _tmp28_;
				if (!_tmp11_) {
					gint _tmp12_;
					_tmp12_ = index;
					index = _tmp12_ + 1;
				}
				_tmp11_ = FALSE;
				_tmp13_ = self->priv->numerics;
				_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
				_tmp15_ = _tmp14_;
				if (!(index < _tmp15_)) {
					break;
				}
				{
					gboolean _tmp16_ = FALSE;
					GRegex* _tmp17_;
					GMatchInfo* _tmp18_ = NULL;
					gboolean _tmp19_;
					_tmp17_ = self->priv->ref_regex;
					_tmp19_ = g_regex_match_full (_tmp17_, text, (gssize) -1, start_pos, 0, &_tmp18_, &_inner_error0_);
					_g_match_info_unref0 (info);
					info = _tmp18_;
					_tmp16_ = _tmp19_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						if (_inner_error0_->domain == G_REGEX_ERROR) {
							goto __catch0_g_regex_error;
						}
						_g_match_info_unref0 (info);
						_g_string_free0 (builder);
						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;
					}
					if (!_tmp16_) {
						break;
					}
				}
				goto __finally0;
				__catch0_g_regex_error:
				{
					g_clear_error (&_inner_error0_);
					g_return_val_if_reached (text);
				}
				__finally0:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_match_info_unref0 (info);
					_g_string_free0 (builder);
					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;
				}
				_tmp20_ = info;
				g_match_info_fetch_pos (_tmp20_, 0, &_tmp21_, &_tmp22_);
				match_start_pos = _tmp21_;
				match_end_pos = _tmp22_;
				_tmp23_ = builder;
				_tmp24_ = string_slice (text, (glong) start_pos, (glong) match_start_pos);
				_tmp25_ = _tmp24_;
				g_string_append (_tmp23_, _tmp25_);
				_g_free0 (_tmp25_);
				_tmp26_ = info;
				_tmp27_ = g_match_info_fetch (_tmp26_, 1);
				type = _tmp27_;
				_tmp28_ = type;
				switch (string_get (_tmp28_, (glong) 0)) {
					case '0':
					case '1':
					case '2':
					case '3':
					case '5':
					case '8':
					{
						GString* _tmp29_;
						GeeArrayList* _tmp30_;
						gpointer _tmp31_;
						const gchar* _tmp32_;
						gchar* _tmp33_;
						gchar* _tmp34_;
						_tmp29_ = builder;
						_tmp30_ = self->priv->numerics;
						_tmp31_ = gee_abstract_list_get ((GeeAbstractList*) _tmp30_, index);
						_tmp32_ = type;
						_tmp33_ = kkc_rom_kana_utils_get_numeric ((gint) ((gintptr) _tmp31_), (KkcNumericConversionType) (string_get (_tmp32_, (glong) 0) - '0'));
						_tmp34_ = _tmp33_;
						g_string_append (_tmp29_, _tmp34_);
						_g_free0 (_tmp34_);
						break;
					}
					case '4':
					case '9':
					{
						GString* _tmp35_;
						GeeArrayList* _tmp36_;
						gpointer _tmp37_;
						gchar* _tmp38_;
						gchar* _tmp39_;
						_tmp35_ = builder;
						_tmp36_ = self->priv->numerics;
						_tmp37_ = gee_abstract_list_get ((GeeAbstractList*) _tmp36_, index);
						_tmp38_ = kkc_rom_kana_utils_get_numeric ((gint) ((gintptr) _tmp37_), KKC_NUMERIC_CONVERSION_TYPE_LATIN);
						_tmp39_ = _tmp38_;
						g_string_append (_tmp35_, _tmp39_);
						_g_free0 (_tmp39_);
						break;
					}
					default:
					{
						const gchar* _tmp40_;
						GString* _tmp41_;
						GeeArrayList* _tmp42_;
						gpointer _tmp43_;
						gchar* _tmp44_;
						gchar* _tmp45_;
						_tmp40_ = type;
						g_warning ("numeric-template.vala:124: unknown numeric conversion type: %s", _tmp40_);
						_tmp41_ = builder;
						_tmp42_ = self->priv->numerics;
						_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp42_, index);
						_tmp44_ = kkc_rom_kana_utils_get_numeric ((gint) ((gintptr) _tmp43_), KKC_NUMERIC_CONVERSION_TYPE_LATIN);
						_tmp45_ = _tmp44_;
						g_string_append (_tmp41_, _tmp45_);
						_g_free0 (_tmp45_);
						break;
					}
				}
				start_pos = match_end_pos;
				_g_free0 (type);
			}
		}
	}
	_tmp46_ = builder;
	_tmp47_ = strlen (text);
	_tmp48_ = _tmp47_;
	_tmp49_ = string_slice (text, (glong) start_pos, (glong) _tmp48_);
	_tmp50_ = _tmp49_;
	g_string_append (_tmp46_, _tmp50_);
	_g_free0 (_tmp50_);
	_tmp51_ = builder;
	_tmp52_ = _tmp51_->str;
	_tmp53_ = g_strdup (_tmp52_);
	result = _tmp53_;
	_g_match_info_unref0 (info);
	_g_string_free0 (builder);
	return result;
}

static const gchar*
kkc_numeric_template_real_get_source (KkcTemplate* base)
{
	const gchar* result;
	KkcNumericTemplate* self;
	const gchar* _tmp0_;
	self = (KkcNumericTemplate*) base;
	_tmp0_ = self->priv->_source;
	result = _tmp0_;
	return result;
}

static void
kkc_numeric_template_real_set_source (KkcTemplate* base,
                                      const gchar* value)
{
	KkcNumericTemplate* self;
	gchar* old_value;
	self = (KkcNumericTemplate*) base;
	old_value = kkc_numeric_template_real_get_source (base);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_source);
		self->priv->_source = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, kkc_numeric_template_properties[KKC_NUMERIC_TEMPLATE_SOURCE_PROPERTY]);
	}
}

static gboolean
kkc_numeric_template_real_get_okuri (KkcTemplate* base)
{
	gboolean result;
	KkcNumericTemplate* self;
	self = (KkcNumericTemplate*) base;
	result = self->priv->_okuri;
	return result;
}

static void
kkc_numeric_template_real_set_okuri (KkcTemplate* base,
                                     gboolean value)
{
	KkcNumericTemplate* self;
	gboolean old_value;
	self = (KkcNumericTemplate*) base;
	old_value = kkc_numeric_template_real_get_okuri (base);
	if (old_value != value) {
		self->priv->_okuri = value;
		g_object_notify_by_pspec ((GObject *) self, kkc_numeric_template_properties[KKC_NUMERIC_TEMPLATE_OKURI_PROPERTY]);
	}
}

static void
kkc_numeric_template_class_init (KkcNumericTemplateClass * klass,
                                 gpointer klass_data)
{
	kkc_numeric_template_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcNumericTemplate_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_numeric_template_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_kkc_numeric_template_set_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_numeric_template_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_NUMERIC_TEMPLATE_SOURCE_PROPERTY, kkc_numeric_template_properties[KKC_NUMERIC_TEMPLATE_SOURCE_PROPERTY] = g_param_spec_string ("source", "source", "source", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_NUMERIC_TEMPLATE_OKURI_PROPERTY, kkc_numeric_template_properties[KKC_NUMERIC_TEMPLATE_OKURI_PROPERTY] = g_param_spec_boolean ("okuri", "okuri", "okuri", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
kkc_numeric_template_kkc_template_interface_init (KkcTemplateIface * iface,
                                                  gpointer iface_data)
{
	kkc_numeric_template_kkc_template_parent_iface = g_type_interface_peek_parent (iface);
	iface->expand = (gchar* (*) (KkcTemplate*, const gchar*)) kkc_numeric_template_real_expand;
	iface->get_source = kkc_numeric_template_real_get_source;
	iface->set_source = kkc_numeric_template_real_set_source;
	iface->get_okuri = kkc_numeric_template_real_get_okuri;
	iface->set_okuri = kkc_numeric_template_real_set_okuri;
}

static void
kkc_numeric_template_instance_init (KkcNumericTemplate * self,
                                    gpointer klass)
{
	GeeArrayList* _tmp0_;
	self->priv = kkc_numeric_template_get_instance_private (self);
	_tmp0_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
	self->priv->numerics = _tmp0_;
}

static void
kkc_numeric_template_finalize (GObject * obj)
{
	KkcNumericTemplate * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplate);
	_g_object_unref0 (self->priv->numerics);
	_g_free0 (self->priv->_source);
	_g_regex_unref0 (self->priv->regex);
	_g_regex_unref0 (self->priv->ref_regex);
	G_OBJECT_CLASS (kkc_numeric_template_parent_class)->finalize (obj);
}

static GType
kkc_numeric_template_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcNumericTemplateClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_numeric_template_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcNumericTemplate), 0, (GInstanceInitFunc) kkc_numeric_template_instance_init, NULL };
	static const GInterfaceInfo kkc_template_info = { (GInterfaceInitFunc) kkc_numeric_template_kkc_template_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_numeric_template_type_id;
	kkc_numeric_template_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcNumericTemplate", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_numeric_template_type_id, KKC_TYPE_TEMPLATE, &kkc_template_info);
	KkcNumericTemplate_private_offset = g_type_add_instance_private (kkc_numeric_template_type_id, sizeof (KkcNumericTemplatePrivate));
	return kkc_numeric_template_type_id;
}

GType
kkc_numeric_template_get_type (void)
{
	static volatile gsize kkc_numeric_template_type_id__once = 0;
	if (g_once_init_enter (&kkc_numeric_template_type_id__once)) {
		GType kkc_numeric_template_type_id;
		kkc_numeric_template_type_id = kkc_numeric_template_get_type_once ();
		g_once_init_leave (&kkc_numeric_template_type_id__once, kkc_numeric_template_type_id);
	}
	return kkc_numeric_template_type_id__once;
}

static void
_vala_kkc_numeric_template_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	KkcNumericTemplate * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplate);
	switch (property_id) {
		case KKC_NUMERIC_TEMPLATE_SOURCE_PROPERTY:
		g_value_set_string (value, kkc_template_get_source ((KkcTemplate*) self));
		break;
		case KKC_NUMERIC_TEMPLATE_OKURI_PROPERTY:
		g_value_set_boolean (value, kkc_template_get_okuri ((KkcTemplate*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_kkc_numeric_template_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec)
{
	KkcNumericTemplate * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplate);
	switch (property_id) {
		case KKC_NUMERIC_TEMPLATE_SOURCE_PROPERTY:
		kkc_template_set_source ((KkcTemplate*) self, g_value_get_string (value));
		break;
		case KKC_NUMERIC_TEMPLATE_OKURI_PROPERTY:
		kkc_template_set_okuri ((KkcTemplate*) self, g_value_get_boolean (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;
}

