/* system-segment-dictionary.c generated by valac 0.56.19, the Vala compiler
 * generated from system-segment-dictionary.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 "libkkc/libkkc.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.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

#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;
enum  {
	KKC_SYSTEM_SEGMENT_DICTIONARY_0_PROPERTY,
	KKC_SYSTEM_SEGMENT_DICTIONARY_NUM_PROPERTIES
};
static GParamSpec* kkc_system_segment_dictionary_properties[KKC_SYSTEM_SEGMENT_DICTIONARY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_mapped_file_unref0(var) ((var == NULL) ? NULL : (var = (g_mapped_file_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _KkcSystemSegmentDictionaryPrivate {
	GFile* file;
	GMappedFile* mmap;
	gchar* etag;
	KkcEncodingConverter* converter;
	glong okuri_ari_offset;
	glong okuri_nasi_offset;
};

static gint KkcSystemSegmentDictionary_private_offset;
static gpointer kkc_system_segment_dictionary_parent_class = NULL;
static KkcDictionaryIface * kkc_system_segment_dictionary_kkc_dictionary_parent_iface = NULL;
static KkcSegmentDictionaryIface * kkc_system_segment_dictionary_kkc_segment_dictionary_parent_iface = NULL;

VALA_EXTERN GType kkc_encoding_converter_get_type (void) G_GNUC_CONST ;
static gchar* kkc_system_segment_dictionary_read_line (KkcSystemSegmentDictionary* self,
                                                glong* offset);
static gchar* kkc_system_segment_dictionary_read_previous_line (KkcSystemSegmentDictionary* self,
                                                         glong* pos,
                                                         const gchar* line);
static gchar* kkc_system_segment_dictionary_read_next_line (KkcSystemSegmentDictionary* self,
                                                     glong* pos,
                                                     const gchar* line);
static gboolean kkc_system_segment_dictionary_read_until (KkcSystemSegmentDictionary* self,
                                                   glong* offset,
                                                   const gchar* line);
static void kkc_system_segment_dictionary_load (KkcSystemSegmentDictionary* self,
                                         GError** error);
VALA_EXTERN gchar* kkc_encoding_converter_extract_coding_system (const gchar* line);
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 void kkc_system_segment_dictionary_real_reload (KkcDictionary* base,
                                                GError** error);
static gboolean kkc_system_segment_dictionary_search_pos (KkcSystemSegmentDictionary* self,
                                                   const gchar* midasi,
                                                   glong start_offset,
                                                   glong end_offset,
                                                   GCompareFunc cmp,
                                                   glong* pos,
                                                   gchar** line,
                                                   gint direction);
static gboolean kkc_system_segment_dictionary_real_lookup_candidates (KkcSegmentDictionary* base,
                                                               const gchar* midasi,
                                                               gboolean okuri,
                                                               KkcCandidate*** candidates,
                                                               gint* candidates_length1);
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 KkcCandidate** kkc_dictionary_utils_split_candidates (const gchar* midasi,
                                                      gboolean okuri,
                                                      const gchar* line,
                                                      gint* result_length1);
static gint kkc_system_segment_dictionary_strcmp_prefix (const gchar* a,
                                                  const gchar* b);
static gchar** kkc_system_segment_dictionary_real_complete (KkcSegmentDictionary* base,
                                                     const gchar* midasi,
                                                     gint* result_length1);
static gint _kkc_system_segment_dictionary_strcmp_prefix_gcompare_func (gconstpointer a,
                                                                 gconstpointer b);
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);
static void kkc_system_segment_dictionary_finalize (GObject * obj);
static GType kkc_system_segment_dictionary_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
kkc_system_segment_dictionary_get_instance_private (KkcSystemSegmentDictionary* self)
{
	return G_STRUCT_MEMBER_P (self, KkcSystemSegmentDictionary_private_offset);
}

static gchar*
kkc_system_segment_dictionary_read_line (KkcSystemSegmentDictionary* self,
                                         glong* offset)
{
	GMappedFile* _tmp0_;
	gchar* p = NULL;
	GMappedFile* _tmp1_;
	gchar* _tmp2_;
	GString* builder = NULL;
	GString* _tmp9_;
	glong _offset = 0L;
	GString* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->mmap;
	g_return_val_if_fail (((gsize) (*offset)) < g_mapped_file_get_length (_tmp0_), NULL);
	_tmp1_ = self->priv->mmap;
	_tmp2_ = g_mapped_file_get_contents (_tmp1_);
	p = ((gchar*) _tmp2_) + (*offset);
	{
		gboolean _tmp3_ = FALSE;
		_tmp3_ = TRUE;
		while (TRUE) {
			gchar* _tmp6_;
			if (!_tmp3_) {
				glong _tmp4_;
				gchar* _tmp5_;
				_tmp4_ = *offset;
				*offset = _tmp4_ - 1;
				_tmp5_ = p;
				p = _tmp5_ - 1;
			}
			_tmp3_ = FALSE;
			if (!((*offset) > ((glong) 0))) {
				break;
			}
			_tmp6_ = p;
			if ((*_tmp6_) == '\n') {
				break;
			}
		}
	}
	if ((*offset) > ((glong) 0)) {
		glong _tmp7_;
		gchar* _tmp8_;
		_tmp7_ = *offset;
		*offset = _tmp7_ + 1;
		_tmp8_ = p;
		p = _tmp8_ + 1;
	}
	_tmp9_ = g_string_new ("");
	builder = _tmp9_;
	_offset = *offset;
	{
		gboolean _tmp10_ = FALSE;
		_tmp10_ = TRUE;
		while (TRUE) {
			GMappedFile* _tmp13_;
			gchar* _tmp14_;
			GString* _tmp15_;
			gchar* _tmp16_;
			if (!_tmp10_) {
				glong _tmp11_;
				gchar* _tmp12_;
				_tmp11_ = _offset;
				_offset = _tmp11_ + 1;
				_tmp12_ = p;
				p = _tmp12_ + 1;
			}
			_tmp10_ = FALSE;
			_tmp13_ = self->priv->mmap;
			if (!(((gsize) _offset) < g_mapped_file_get_length (_tmp13_))) {
				break;
			}
			_tmp14_ = p;
			if ((*_tmp14_) == '\n') {
				break;
			}
			_tmp15_ = builder;
			_tmp16_ = p;
			g_string_append_c (_tmp15_, *_tmp16_);
		}
	}
	_tmp17_ = builder;
	_tmp18_ = _tmp17_->str;
	_tmp19_ = g_strdup (_tmp18_);
	result = _tmp19_;
	_g_string_free0 (builder);
	return result;
}

static gchar*
kkc_system_segment_dictionary_read_previous_line (KkcSystemSegmentDictionary* self,
                                                  glong* pos,
                                                  const gchar* line)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (line != NULL, NULL);
	if ((*pos) < ((glong) 2)) {
		result = NULL;
		return result;
	}
	*pos = (*pos) - 2;
	_tmp0_ = kkc_system_segment_dictionary_read_line (self, pos);
	result = _tmp0_;
	return result;
}

static gchar*
kkc_system_segment_dictionary_read_next_line (KkcSystemSegmentDictionary* self,
                                              glong* pos,
                                              const gchar* line)
{
	gint _tmp0_;
	gint _tmp1_;
	GMappedFile* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (line != NULL, NULL);
	_tmp0_ = strlen (line);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->mmap;
	if (((gsize) (((*pos) + _tmp1_) + 1)) >= g_mapped_file_get_length (_tmp2_)) {
		result = NULL;
		return result;
	}
	_tmp3_ = strlen (line);
	_tmp4_ = _tmp3_;
	*pos = (*pos) + (_tmp4_ + 1);
	_tmp5_ = kkc_system_segment_dictionary_read_line (self, pos);
	result = _tmp5_;
	return result;
}

static gboolean
kkc_system_segment_dictionary_read_until (KkcSystemSegmentDictionary* self,
                                          glong* offset,
                                          const gchar* line)
{
	GMappedFile* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (line != NULL, FALSE);
	_tmp0_ = self->priv->mmap;
	g_return_val_if_fail (((gsize) (*offset)) < g_mapped_file_get_length (_tmp0_), FALSE);
	while (TRUE) {
		gint _tmp1_;
		gint _tmp2_;
		GMappedFile* _tmp3_;
		gchar* p = NULL;
		GMappedFile* _tmp4_;
		gchar* _tmp5_;
		gboolean _tmp6_ = FALSE;
		gchar* _tmp7_;
		glong _tmp13_;
		_tmp1_ = strlen (line);
		_tmp2_ = _tmp1_;
		_tmp3_ = self->priv->mmap;
		if (!(((gsize) ((*offset) + _tmp2_)) < g_mapped_file_get_length (_tmp3_))) {
			break;
		}
		_tmp4_ = self->priv->mmap;
		_tmp5_ = g_mapped_file_get_contents (_tmp4_);
		p = ((gchar*) _tmp5_) + (*offset);
		_tmp7_ = p;
		if ((*_tmp7_) == '\n') {
			gchar* _tmp8_;
			gint _tmp9_;
			gint _tmp10_;
			_tmp8_ = p;
			_tmp9_ = strlen (line);
			_tmp10_ = _tmp9_;
			_tmp6_ = memcmp (_tmp8_ + 1, (void*) line, (gsize) _tmp10_) == 0;
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			gint _tmp11_;
			gint _tmp12_;
			_tmp11_ = strlen (line);
			_tmp12_ = _tmp11_;
			*offset = (*offset) + _tmp12_;
			result = TRUE;
			return result;
		}
		_tmp13_ = *offset;
		*offset = _tmp13_ + 1;
	}
	result = FALSE;
	return result;
}

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

static void
kkc_system_segment_dictionary_load (KkcSystemSegmentDictionary* self,
                                    GError** error)
{
	GMappedFile* _tmp0_ = NULL;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GMappedFile* _tmp4_;
	GMappedFile* _tmp5_;
	GMappedFile* _tmp6_;
	glong offset = 0L;
	gchar* line = NULL;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* coding = NULL;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp21_;
	gboolean _tmp24_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->file;
	_tmp2_ = g_file_get_path (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_mapped_file_new (_tmp3_, FALSE, &_inner_error0_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_tmp0_ = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp6_ = _tmp0_;
	_tmp0_ = NULL;
	_g_mapped_file_unref0 (self->priv->mmap);
	self->priv->mmap = _tmp6_;
	offset = (glong) 0;
	_tmp7_ = kkc_system_segment_dictionary_read_line (self, &offset);
	line = _tmp7_;
	_tmp8_ = line;
	if (_tmp8_ == NULL) {
		GError* _tmp9_;
		_tmp9_ = g_error_new_literal (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "can't read the first line");
		_inner_error0_ = _tmp9_;
		g_propagate_error (error, _inner_error0_);
		_g_free0 (line);
		_g_mapped_file_unref0 (_tmp0_);
		return;
	}
	_tmp10_ = line;
	_tmp11_ = kkc_encoding_converter_extract_coding_system (_tmp10_);
	coding = _tmp11_;
	_tmp12_ = coding;
	if (_tmp12_ != NULL) {
		{
			KkcEncodingConverter* _converter = NULL;
			const gchar* _tmp13_;
			KkcEncodingConverter* _tmp14_;
			KkcEncodingConverter* _tmp15_;
			_tmp13_ = coding;
			_tmp14_ = kkc_encoding_converter_new_from_coding_system (_tmp13_, &_inner_error0_);
			_converter = _tmp14_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp15_ = _converter;
			if (_tmp15_ != NULL) {
				KkcEncodingConverter* _tmp16_;
				KkcEncodingConverter* _tmp17_;
				_tmp16_ = _converter;
				_tmp17_ = _g_object_ref0 (_tmp16_);
				_g_object_unref0 (self->priv->converter);
				self->priv->converter = _tmp17_;
			}
			_g_object_unref0 (_converter);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			const gchar* _tmp18_;
			GError* _tmp19_;
			const gchar* _tmp20_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp18_ = coding;
			_tmp19_ = e;
			_tmp20_ = _tmp19_->message;
			g_warning ("system-segment-dictionary.vala:104: can't create converter from coding" \
" system %s: %s", _tmp18_, _tmp20_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (coding);
			_g_free0 (line);
			_g_mapped_file_unref0 (_tmp0_);
			return;
		}
	}
	_tmp21_ = line;
	if (g_strcmp0 (_tmp21_, ";; okuri-ari entries.") == 0) {
		offset = (glong) 0;
	} else {
		gboolean _tmp22_;
		_tmp22_ = kkc_system_segment_dictionary_read_until (self, &offset, ";; okuri-ari entries.\n");
		if (!_tmp22_) {
			GError* _tmp23_;
			_tmp23_ = g_error_new_literal (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "no okuri-ari boundary");
			_inner_error0_ = _tmp23_;
			g_propagate_error (error, _inner_error0_);
			_g_free0 (coding);
			_g_free0 (line);
			_g_mapped_file_unref0 (_tmp0_);
			return;
		}
	}
	self->priv->okuri_ari_offset = offset;
	_tmp24_ = kkc_system_segment_dictionary_read_until (self, &offset, ";; okuri-nasi entries.\n");
	if (!_tmp24_) {
		GError* _tmp25_;
		_tmp25_ = g_error_new_literal (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "no okuri-nasi boundary");
		_inner_error0_ = _tmp25_;
		g_propagate_error (error, _inner_error0_);
		_g_free0 (coding);
		_g_free0 (line);
		_g_mapped_file_unref0 (_tmp0_);
		return;
	}
	self->priv->okuri_nasi_offset = offset;
	_g_free0 (coding);
	_g_free0 (line);
	_g_mapped_file_unref0 (_tmp0_);
}

/**
         * {@inheritDoc}
         */
static void
kkc_system_segment_dictionary_real_reload (KkcDictionary* base,
                                           GError** error)
{
	KkcSystemSegmentDictionary * self;
	gchar* attributes = NULL;
	gchar* _tmp0_;
	GFileInfo* info = NULL;
	GFile* _tmp1_;
	const gchar* _tmp2_;
	GFileInfo* _tmp3_;
	GFileInfo* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	GError* _inner_error0_ = NULL;
	self = (KkcSystemSegmentDictionary*) base;
	_tmp0_ = g_strdup (G_FILE_ATTRIBUTE_ETAG_VALUE);
	attributes = _tmp0_;
	_tmp1_ = self->priv->file;
	_tmp2_ = attributes;
	_tmp3_ = g_file_query_info (_tmp1_, _tmp2_, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
	info = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (attributes);
		return;
	}
	_tmp4_ = info;
	_tmp5_ = g_file_info_get_etag (_tmp4_);
	_tmp6_ = self->priv->etag;
	if (g_strcmp0 (_tmp5_, _tmp6_) != 0) {
		GFileInfo* _tmp7_;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		kkc_system_segment_dictionary_load (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (info);
			_g_free0 (attributes);
			return;
		}
		_tmp7_ = info;
		_tmp8_ = g_file_info_get_etag (_tmp7_);
		_tmp9_ = g_strdup (_tmp8_);
		_g_free0 (self->priv->etag);
		self->priv->etag = _tmp9_;
	}
	_g_object_unref0 (info);
	_g_free0 (attributes);
}

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

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 gboolean
kkc_system_segment_dictionary_search_pos (KkcSystemSegmentDictionary* self,
                                          const gchar* midasi,
                                          glong start_offset,
                                          glong end_offset,
                                          GCompareFunc cmp,
                                          glong* pos,
                                          gchar** line,
                                          gint direction)
{
	glong _vala_pos = 0L;
	gchar* _vala_line = NULL;
	glong offset = 0L;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (midasi != NULL, FALSE);
	offset = start_offset + ((end_offset - start_offset) / 2);
	while (TRUE) {
		GMappedFile* _tmp0_;
		gchar* _line = NULL;
		gchar* _tmp1_;
		gint index = 0;
		const gchar* _tmp2_;
		gint r = 0;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gint _tmp7_;
		if (!(start_offset <= end_offset)) {
			break;
		}
		_tmp0_ = self->priv->mmap;
		_vala_assert (((gsize) offset) < g_mapped_file_get_length (_tmp0_), "offset < mmap.get_length ()");
		_tmp1_ = kkc_system_segment_dictionary_read_line (self, &offset);
		_line = _tmp1_;
		_tmp2_ = _line;
		index = string_index_of (_tmp2_, " ", 0);
		if (index < 1) {
			const gchar* _tmp3_;
			_tmp3_ = _line;
			g_warning ("system-segment-dictionary.vala:150: corrupted dictionary entry: %s", _tmp3_);
			_g_free0 (_line);
			break;
		}
		_tmp4_ = _line;
		_tmp5_ = string_slice (_tmp4_, (glong) 0, (glong) index);
		_tmp6_ = _tmp5_;
		_tmp7_ = cmp (_tmp6_, midasi);
		_g_free0 (_tmp6_);
		r = _tmp7_;
		if (r == 0) {
			const gchar* _tmp8_;
			gchar* _tmp9_;
			_vala_pos = offset;
			_tmp8_ = _line;
			_tmp9_ = g_strdup (_tmp8_);
			_g_free0 (_vala_line);
			_vala_line = _tmp9_;
			result = TRUE;
			_g_free0 (_line);
			if (pos) {
				*pos = _vala_pos;
			}
			if (line) {
				*line = _vala_line;
			} else {
				_g_free0 (_vala_line);
			}
			return result;
		}
		if ((r * direction) > 0) {
			end_offset = offset - 2;
		} else {
			const gchar* _tmp10_;
			gint _tmp11_;
			gint _tmp12_;
			_tmp10_ = _line;
			_tmp11_ = strlen (_tmp10_);
			_tmp12_ = _tmp11_;
			start_offset = (offset + _tmp12_) + 1;
		}
		offset = start_offset + ((end_offset - start_offset) / 2);
		_g_free0 (_line);
	}
	_vala_pos = (glong) -1;
	_g_free0 (_vala_line);
	_vala_line = NULL;
	result = FALSE;
	if (pos) {
		*pos = _vala_pos;
	}
	if (line) {
		*line = _vala_line;
	} else {
		_g_free0 (_vala_line);
	}
	return result;
}

/**
         * {@inheritDoc}
         */
static gboolean
kkc_system_segment_dictionary_real_lookup_candidates (KkcSegmentDictionary* base,
                                                      const gchar* midasi,
                                                      gboolean okuri,
                                                      KkcCandidate*** candidates,
                                                      gint* candidates_length1)
{
	KkcSystemSegmentDictionary * self;
	KkcCandidate** _vala_candidates = NULL;
	gint _vala_candidates_length1 = 0;
	GMappedFile* _tmp0_;
	gchar* _tmp1_;
	glong start_offset = 0L;
	glong end_offset = 0L;
	gchar* _midasi = NULL;
	glong pos = 0L;
	gchar* line = NULL;
	gint _tmp12_ = 0;
	const gchar* _tmp13_;
	GCompareFunc _tmp14_;
	glong _tmp15_ = 0L;
	gchar* _tmp16_ = NULL;
	gboolean _tmp17_;
	KkcCandidate** _tmp38_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (KkcSystemSegmentDictionary*) base;
	g_return_val_if_fail (midasi != NULL, FALSE);
	_tmp0_ = self->priv->mmap;
	_tmp1_ = g_mapped_file_get_contents (_tmp0_);
	if (_tmp1_ == NULL) {
		KkcCandidate** _tmp2_;
		_tmp2_ = g_new0 (KkcCandidate*, 0 + 1);
		_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_vala_candidates = _tmp2_;
		_vala_candidates_length1 = 0;
		result = FALSE;
		if (candidates) {
			*candidates = _vala_candidates;
		} else {
			_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		}
		if (candidates_length1) {
			*candidates_length1 = _vala_candidates_length1;
		}
		return result;
	}
	if (okuri) {
		start_offset = self->priv->okuri_ari_offset;
		end_offset = self->priv->okuri_nasi_offset;
	} else {
		GMappedFile* _tmp3_;
		start_offset = self->priv->okuri_nasi_offset;
		_tmp3_ = self->priv->mmap;
		end_offset = ((glong) g_mapped_file_get_length (_tmp3_)) - 1;
	}
	{
		gchar* _tmp4_ = NULL;
		KkcEncodingConverter* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp5_ = self->priv->converter;
		_tmp6_ = kkc_encoding_converter_encode (_tmp5_, midasi, &_inner_error0_);
		_tmp4_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp7_ = _tmp4_;
		_tmp4_ = NULL;
		_g_free0 (_midasi);
		_midasi = _tmp7_;
		_g_free0 (_tmp4_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp8_;
		const gchar* _tmp9_;
		KkcCandidate** _tmp10_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		g_warning ("system-segment-dictionary.vala:196: can't encode %s: %s", midasi, _tmp9_);
		_tmp10_ = g_new0 (KkcCandidate*, 0 + 1);
		_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_vala_candidates = _tmp10_;
		_vala_candidates_length1 = 0;
		result = FALSE;
		_g_error_free0 (e);
		_g_free0 (_midasi);
		if (candidates) {
			*candidates = _vala_candidates;
		} else {
			_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		}
		if (candidates_length1) {
			*candidates_length1 = _vala_candidates_length1;
		}
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp11_ = FALSE;
		_g_free0 (_midasi);
		_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), 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 _tmp11_;
	}
	if (okuri) {
		_tmp12_ = -1;
	} else {
		_tmp12_ = 1;
	}
	_tmp13_ = _midasi;
	_tmp14_ = ((GCompareFunc) g_strcmp0);
	_tmp17_ = kkc_system_segment_dictionary_search_pos (self, _tmp13_, start_offset, end_offset, _tmp14_, &_tmp15_, &_tmp16_, _tmp12_);
	pos = _tmp15_;
	_g_free0 (line);
	line = _tmp16_;
	if (_tmp17_) {
		gint index = 0;
		const gchar* _tmp18_;
		gchar* _line = NULL;
		_tmp18_ = line;
		index = string_index_of (_tmp18_, " ", 0);
		if (index > 0) {
			const gchar* _tmp35_;
			gint _tmp36_ = 0;
			KkcCandidate** _tmp37_;
			{
				gchar* _tmp19_ = NULL;
				KkcEncodingConverter* _tmp20_;
				const gchar* _tmp21_;
				const gchar* _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				gchar* _tmp25_;
				gchar* _tmp26_;
				gchar* _tmp27_;
				gchar* _tmp28_;
				gchar* _tmp29_;
				_tmp20_ = self->priv->converter;
				_tmp21_ = line;
				_tmp22_ = line;
				_tmp23_ = strlen (_tmp22_);
				_tmp24_ = _tmp23_;
				_tmp25_ = string_slice (_tmp21_, (glong) index, (glong) _tmp24_);
				_tmp26_ = _tmp25_;
				_tmp27_ = kkc_encoding_converter_decode (_tmp20_, _tmp26_, &_inner_error0_);
				_tmp28_ = _tmp27_;
				_g_free0 (_tmp26_);
				_tmp19_ = _tmp28_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch1_g_error;
				}
				_tmp29_ = _tmp19_;
				_tmp19_ = NULL;
				_g_free0 (_line);
				_line = _tmp29_;
				_g_free0 (_tmp19_);
			}
			goto __finally1;
			__catch1_g_error:
			{
				GError* e = NULL;
				const gchar* _tmp30_;
				GError* _tmp31_;
				const gchar* _tmp32_;
				KkcCandidate** _tmp33_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp30_ = line;
				_tmp31_ = e;
				_tmp32_ = _tmp31_->message;
				g_warning ("system-segment-dictionary.vala:216: can't decode line %s: %s", _tmp30_, _tmp32_);
				_tmp33_ = g_new0 (KkcCandidate*, 0 + 1);
				_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
				_vala_candidates = _tmp33_;
				_vala_candidates_length1 = 0;
				result = FALSE;
				_g_error_free0 (e);
				_g_free0 (_line);
				_g_free0 (line);
				_g_free0 (_midasi);
				if (candidates) {
					*candidates = _vala_candidates;
				} else {
					_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
				}
				if (candidates_length1) {
					*candidates_length1 = _vala_candidates_length1;
				}
				return result;
			}
			__finally1:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp34_ = FALSE;
				_g_free0 (_line);
				_g_free0 (line);
				_g_free0 (_midasi);
				_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), 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 _tmp34_;
			}
			_tmp35_ = _line;
			_tmp37_ = kkc_dictionary_utils_split_candidates (midasi, okuri, _tmp35_, &_tmp36_);
			_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
			_vala_candidates = _tmp37_;
			_vala_candidates_length1 = _tmp36_;
			result = TRUE;
			_g_free0 (_line);
			_g_free0 (line);
			_g_free0 (_midasi);
			if (candidates) {
				*candidates = _vala_candidates;
			} else {
				_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
			}
			if (candidates_length1) {
				*candidates_length1 = _vala_candidates_length1;
			}
			return result;
		}
		_g_free0 (_line);
	}
	_tmp38_ = g_new0 (KkcCandidate*, 0 + 1);
	_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	_vala_candidates = _tmp38_;
	_vala_candidates_length1 = 0;
	result = FALSE;
	_g_free0 (line);
	_g_free0 (_midasi);
	if (candidates) {
		*candidates = _vala_candidates;
	} else {
		_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	}
	if (candidates_length1) {
		*candidates_length1 = _vala_candidates_length1;
	}
	return result;
}

static gint
kkc_system_segment_dictionary_strcmp_prefix (const gchar* a,
                                             const gchar* b)
{
	GCompareFunc _tmp0_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	if (g_str_has_prefix (a, b)) {
		result = 0;
		return result;
	}
	_tmp0_ = ((GCompareFunc) g_strcmp0);
	result = _tmp0_ (a, b);
	return result;
}

/**
         * {@inheritDoc}
         */
static gint
_kkc_system_segment_dictionary_strcmp_prefix_gcompare_func (gconstpointer a,
                                                            gconstpointer b)
{
	gint result;
	result = kkc_system_segment_dictionary_strcmp_prefix ((const gchar*) a, (const gchar*) b);
	return result;
}

static gchar**
kkc_system_segment_dictionary_real_complete (KkcSegmentDictionary* base,
                                             const gchar* midasi,
                                             gint* result_length1)
{
	KkcSystemSegmentDictionary * self;
	GMappedFile* _tmp0_;
	gchar* _tmp1_;
	GeeArrayList* completion = NULL;
	GeeArrayList* _tmp4_;
	glong start_offset = 0L;
	glong end_offset = 0L;
	GMappedFile* _tmp5_;
	gchar* _midasi = NULL;
	glong pos = 0L;
	gchar* line = NULL;
	const gchar* _tmp16_;
	glong _tmp17_ = 0L;
	gchar* _tmp18_ = NULL;
	gboolean _tmp19_;
	GeeArrayList* _tmp69_;
	gint _tmp70_ = 0;
	gpointer* _tmp71_;
	gchar** _tmp72_;
	gint _tmp72__length1;
	GError* _inner_error0_ = NULL;
	gchar** result;
	self = (KkcSystemSegmentDictionary*) base;
	g_return_val_if_fail (midasi != NULL, NULL);
	_tmp0_ = self->priv->mmap;
	_tmp1_ = g_mapped_file_get_contents (_tmp0_);
	if (_tmp1_ == NULL) {
		gchar** _tmp2_;
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp2_ = g_new0 (gchar*, 0 + 1);
		_tmp3_ = _tmp2_;
		_tmp3__length1 = 0;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		return result;
	}
	_tmp4_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	completion = _tmp4_;
	start_offset = self->priv->okuri_nasi_offset;
	_tmp5_ = self->priv->mmap;
	end_offset = ((glong) g_mapped_file_get_length (_tmp5_)) - 1;
	{
		gchar* _tmp6_ = NULL;
		KkcEncodingConverter* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp7_ = self->priv->converter;
		_tmp8_ = kkc_encoding_converter_encode (_tmp7_, midasi, &_inner_error0_);
		_tmp6_ = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp9_ = _tmp6_;
		_tmp6_ = NULL;
		_g_free0 (_midasi);
		_midasi = _tmp9_;
		_g_free0 (_tmp6_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp10_;
		const gchar* _tmp11_;
		GeeArrayList* _tmp12_;
		gint _tmp13_ = 0;
		gpointer* _tmp14_;
		gchar** _tmp15_;
		gint _tmp15__length1;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp10_ = e;
		_tmp11_ = _tmp10_->message;
		g_warning ("system-segment-dictionary.vala:254: can't decode %s: %s", midasi, _tmp11_);
		_tmp12_ = completion;
		_tmp14_ = gee_collection_to_array ((GeeCollection*) _tmp12_, &_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp15__length1 = _tmp13_;
		if (result_length1) {
			*result_length1 = _tmp15__length1;
		}
		result = _tmp15_;
		_g_error_free0 (e);
		_g_free0 (_midasi);
		_g_object_unref0 (completion);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (_midasi);
		_g_object_unref0 (completion);
		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;
	}
	_tmp16_ = _midasi;
	_tmp19_ = kkc_system_segment_dictionary_search_pos (self, _tmp16_, start_offset, end_offset, _kkc_system_segment_dictionary_strcmp_prefix_gcompare_func, &_tmp17_, &_tmp18_, 1);
	pos = _tmp17_;
	_g_free0 (line);
	line = _tmp18_;
	if (_tmp19_) {
		glong _pos = 0L;
		gchar* _line = NULL;
		const gchar* _tmp20_;
		gchar* _tmp21_;
		const gchar* _tmp45_;
		gchar* _tmp46_;
		_pos = pos;
		_tmp20_ = line;
		_tmp21_ = g_strdup (_tmp20_);
		_line = _tmp21_;
		{
			gboolean _tmp22_ = FALSE;
			_tmp22_ = TRUE;
			while (TRUE) {
				gint index = 0;
				const gchar* _tmp29_;
				if (!_tmp22_) {
					gboolean _tmp23_ = FALSE;
					const gchar* _tmp24_;
					gchar* _tmp25_;
					const gchar* _tmp26_;
					_tmp24_ = line;
					_tmp25_ = kkc_system_segment_dictionary_read_previous_line (self, &pos, _tmp24_);
					_g_free0 (line);
					line = _tmp25_;
					_tmp26_ = line;
					if (_tmp26_ != NULL) {
						const gchar* _tmp27_;
						const gchar* _tmp28_;
						_tmp27_ = line;
						_tmp28_ = _midasi;
						_tmp23_ = g_str_has_prefix (_tmp27_, _tmp28_);
					} else {
						_tmp23_ = FALSE;
					}
					if (!_tmp23_) {
						break;
					}
				}
				_tmp22_ = FALSE;
				_tmp29_ = line;
				index = string_index_of (_tmp29_, " ", 0);
				if (index < 0) {
					const gchar* _tmp30_;
					_tmp30_ = line;
					g_warning ("system-segment-dictionary.vala:274: corrupted dictionary entry: %s", _tmp30_);
				} else {
					gchar* completed = NULL;
					const gchar* _tmp31_;
					gchar* _tmp32_;
					gboolean _tmp33_ = FALSE;
					const gchar* _tmp34_;
					const gchar* _tmp35_;
					_tmp31_ = line;
					_tmp32_ = string_slice (_tmp31_, (glong) 0, (glong) index);
					completed = _tmp32_;
					_tmp34_ = completed;
					_tmp35_ = _midasi;
					if (g_strcmp0 (_tmp34_, _tmp35_) != 0) {
						const gchar* _tmp36_;
						_tmp36_ = completed;
						_tmp33_ = !g_str_has_suffix (_tmp36_, ">");
					} else {
						_tmp33_ = FALSE;
					}
					if (_tmp33_) {
						{
							gchar* decoded = NULL;
							KkcEncodingConverter* _tmp37_;
							const gchar* _tmp38_;
							gchar* _tmp39_;
							GeeArrayList* _tmp40_;
							const gchar* _tmp41_;
							_tmp37_ = self->priv->converter;
							_tmp38_ = completed;
							_tmp39_ = kkc_encoding_converter_decode (_tmp37_, _tmp38_, &_inner_error0_);
							decoded = _tmp39_;
							if (G_UNLIKELY (_inner_error0_ != NULL)) {
								goto __catch1_g_error;
							}
							_tmp40_ = completion;
							_tmp41_ = decoded;
							gee_abstract_list_insert ((GeeAbstractList*) _tmp40_, 0, _tmp41_);
							_g_free0 (decoded);
						}
						goto __finally1;
						__catch1_g_error:
						{
							GError* e = NULL;
							const gchar* _tmp42_;
							GError* _tmp43_;
							const gchar* _tmp44_;
							e = _inner_error0_;
							_inner_error0_ = NULL;
							_tmp42_ = line;
							_tmp43_ = e;
							_tmp44_ = _tmp43_->message;
							g_warning ("system-segment-dictionary.vala:285: can't decode line %s: %s", _tmp42_, _tmp44_);
							_g_error_free0 (e);
						}
						__finally1:
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_free0 (completed);
							_g_free0 (_line);
							_g_free0 (line);
							_g_free0 (_midasi);
							_g_object_unref0 (completion);
							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;
						}
					}
					_g_free0 (completed);
				}
			}
		}
		pos = _pos;
		_tmp45_ = _line;
		_tmp46_ = g_strdup (_tmp45_);
		_g_free0 (line);
		line = _tmp46_;
		while (TRUE) {
			gboolean _tmp47_ = FALSE;
			const gchar* _tmp48_;
			gchar* _tmp49_;
			const gchar* _tmp50_;
			gint index = 0;
			const gchar* _tmp53_;
			_tmp48_ = line;
			_tmp49_ = kkc_system_segment_dictionary_read_next_line (self, &pos, _tmp48_);
			_g_free0 (line);
			line = _tmp49_;
			_tmp50_ = line;
			if (_tmp50_ != NULL) {
				const gchar* _tmp51_;
				const gchar* _tmp52_;
				_tmp51_ = line;
				_tmp52_ = _midasi;
				_tmp47_ = g_str_has_prefix (_tmp51_, _tmp52_);
			} else {
				_tmp47_ = FALSE;
			}
			if (!_tmp47_) {
				break;
			}
			_tmp53_ = line;
			index = string_index_of (_tmp53_, " ", 0);
			if (index < 0) {
				const gchar* _tmp54_;
				_tmp54_ = line;
				g_warning ("system-segment-dictionary.vala:300: corrupted dictionary entry: %s", _tmp54_);
			} else {
				gchar* completed = NULL;
				const gchar* _tmp55_;
				gchar* _tmp56_;
				gboolean _tmp57_ = FALSE;
				const gchar* _tmp58_;
				const gchar* _tmp59_;
				_tmp55_ = line;
				_tmp56_ = string_slice (_tmp55_, (glong) 0, (glong) index);
				completed = _tmp56_;
				_tmp58_ = completed;
				_tmp59_ = _midasi;
				if (g_strcmp0 (_tmp58_, _tmp59_) != 0) {
					const gchar* _tmp60_;
					_tmp60_ = completed;
					_tmp57_ = !g_str_has_suffix (_tmp60_, ">");
				} else {
					_tmp57_ = FALSE;
				}
				if (_tmp57_) {
					{
						gchar* decoded = NULL;
						KkcEncodingConverter* _tmp61_;
						const gchar* _tmp62_;
						gchar* _tmp63_;
						GeeArrayList* _tmp64_;
						const gchar* _tmp65_;
						_tmp61_ = self->priv->converter;
						_tmp62_ = completed;
						_tmp63_ = kkc_encoding_converter_decode (_tmp61_, _tmp62_, &_inner_error0_);
						decoded = _tmp63_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							goto __catch2_g_error;
						}
						_tmp64_ = completion;
						_tmp65_ = decoded;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp64_, _tmp65_);
						_g_free0 (decoded);
					}
					goto __finally2;
					__catch2_g_error:
					{
						GError* e = NULL;
						const gchar* _tmp66_;
						GError* _tmp67_;
						const gchar* _tmp68_;
						e = _inner_error0_;
						_inner_error0_ = NULL;
						_tmp66_ = line;
						_tmp67_ = e;
						_tmp68_ = _tmp67_->message;
						g_warning ("system-segment-dictionary.vala:311: can't decode line %s: %s", _tmp66_, _tmp68_);
						_g_error_free0 (e);
					}
					__finally2:
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_free0 (completed);
						_g_free0 (_line);
						_g_free0 (line);
						_g_free0 (_midasi);
						_g_object_unref0 (completion);
						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;
					}
				}
				_g_free0 (completed);
			}
		}
		_g_free0 (_line);
	}
	_tmp69_ = completion;
	_tmp71_ = gee_collection_to_array ((GeeCollection*) _tmp69_, &_tmp70_);
	_tmp72_ = _tmp71_;
	_tmp72__length1 = _tmp70_;
	if (result_length1) {
		*result_length1 = _tmp72__length1;
	}
	result = _tmp72_;
	_g_free0 (line);
	_g_free0 (_midasi);
	_g_object_unref0 (completion);
	return result;
}

/**
         * Create a new SystemSegmentDictionary.
         *
         * @param path a path to the file
         * @param encoding encoding of the file (default EUC-JP)
         *
         * @return a new FileDictionary
         * @throws GLib.Error if opening the file is failed
         */
KkcSystemSegmentDictionary*
kkc_system_segment_dictionary_construct (GType object_type,
                                         const gchar* path,
                                         const gchar* encoding,
                                         GError** error)
{
	KkcSystemSegmentDictionary * self = NULL;
	GFile* _tmp0_;
	gchar* _tmp1_;
	KkcEncodingConverter* _tmp2_ = NULL;
	KkcEncodingConverter* _tmp3_;
	KkcEncodingConverter* _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	g_return_val_if_fail (encoding != NULL, NULL);
	self = (KkcSystemSegmentDictionary*) g_object_new (object_type, NULL);
	_tmp0_ = g_file_new_for_path (path);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp0_;
	_tmp1_ = g_strdup ("");
	_g_free0 (self->priv->etag);
	self->priv->etag = _tmp1_;
	_tmp3_ = kkc_encoding_converter_new (encoding, &_inner_error0_);
	_tmp2_ = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (self);
		return NULL;
	}
	_tmp4_ = _tmp2_;
	_tmp2_ = NULL;
	_g_object_unref0 (self->priv->converter);
	self->priv->converter = _tmp4_;
	kkc_system_segment_dictionary_load (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp2_);
		_g_object_unref0 (self);
		return NULL;
	}
	_g_object_unref0 (_tmp2_);
	return self;
}

KkcSystemSegmentDictionary*
kkc_system_segment_dictionary_new (const gchar* path,
                                   const gchar* encoding,
                                   GError** error)
{
	return kkc_system_segment_dictionary_construct (KKC_TYPE_SYSTEM_SEGMENT_DICTIONARY, path, encoding, error);
}

static void
kkc_system_segment_dictionary_class_init (KkcSystemSegmentDictionaryClass * klass,
                                          gpointer klass_data)
{
	kkc_system_segment_dictionary_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcSystemSegmentDictionary_private_offset);
	G_OBJECT_CLASS (klass)->finalize = kkc_system_segment_dictionary_finalize;
}

static void
kkc_system_segment_dictionary_kkc_dictionary_interface_init (KkcDictionaryIface * iface,
                                                             gpointer iface_data)
{
	kkc_system_segment_dictionary_kkc_dictionary_parent_iface = g_type_interface_peek_parent (iface);
	iface->reload = (void (*) (KkcDictionary*, GError**)) kkc_system_segment_dictionary_real_reload;
}

static void
kkc_system_segment_dictionary_kkc_segment_dictionary_interface_init (KkcSegmentDictionaryIface * iface,
                                                                     gpointer iface_data)
{
	kkc_system_segment_dictionary_kkc_segment_dictionary_parent_iface = g_type_interface_peek_parent (iface);
	iface->lookup_candidates = (gboolean (*) (KkcSegmentDictionary*, const gchar*, gboolean, KkcCandidate***, gint*)) kkc_system_segment_dictionary_real_lookup_candidates;
	iface->complete = (gchar** (*) (KkcSegmentDictionary*, const gchar*, gint*)) kkc_system_segment_dictionary_real_complete;
}

static void
kkc_system_segment_dictionary_instance_init (KkcSystemSegmentDictionary * self,
                                             gpointer klass)
{
	self->priv = kkc_system_segment_dictionary_get_instance_private (self);
}

static void
kkc_system_segment_dictionary_finalize (GObject * obj)
{
	KkcSystemSegmentDictionary * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_SYSTEM_SEGMENT_DICTIONARY, KkcSystemSegmentDictionary);
	_g_object_unref0 (self->priv->file);
	_g_mapped_file_unref0 (self->priv->mmap);
	_g_free0 (self->priv->etag);
	_g_object_unref0 (self->priv->converter);
	G_OBJECT_CLASS (kkc_system_segment_dictionary_parent_class)->finalize (obj);
}

/**
     * Read-only file based implementation of Dictionary.
     */
static GType
kkc_system_segment_dictionary_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcSystemSegmentDictionaryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_system_segment_dictionary_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcSystemSegmentDictionary), 0, (GInstanceInitFunc) kkc_system_segment_dictionary_instance_init, NULL };
	static const GInterfaceInfo kkc_dictionary_info = { (GInterfaceInitFunc) kkc_system_segment_dictionary_kkc_dictionary_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo kkc_segment_dictionary_info = { (GInterfaceInitFunc) kkc_system_segment_dictionary_kkc_segment_dictionary_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_system_segment_dictionary_type_id;
	kkc_system_segment_dictionary_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcSystemSegmentDictionary", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_system_segment_dictionary_type_id, KKC_TYPE_DICTIONARY, &kkc_dictionary_info);
	g_type_add_interface_static (kkc_system_segment_dictionary_type_id, KKC_TYPE_SEGMENT_DICTIONARY, &kkc_segment_dictionary_info);
	KkcSystemSegmentDictionary_private_offset = g_type_add_instance_private (kkc_system_segment_dictionary_type_id, sizeof (KkcSystemSegmentDictionaryPrivate));
	return kkc_system_segment_dictionary_type_id;
}

GType
kkc_system_segment_dictionary_get_type (void)
{
	static volatile gsize kkc_system_segment_dictionary_type_id__once = 0;
	if (g_once_init_enter (&kkc_system_segment_dictionary_type_id__once)) {
		GType kkc_system_segment_dictionary_type_id;
		kkc_system_segment_dictionary_type_id = kkc_system_segment_dictionary_get_type_once ();
		g_once_init_leave (&kkc_system_segment_dictionary_type_id__once, kkc_system_segment_dictionary_type_id);
	}
	return kkc_system_segment_dictionary_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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;
}

