/* mime-data-format.c generated by valac 0.56.3, the Vala compiler
 * generated from mime-data-format.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include <glib.h>
#include "geary-engine.h"
#include <stdlib.h>
#include <string.h>

static gboolean _vala_char_array_contains (gchar * stack,
                                    gssize stack_length,
                                    const gchar needle);

const gchar GEARY_MIME_DATA_FORMAT_CONTENT_TYPE_TOKEN_SPECIALS[15] = {'(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '='};

 G_GNUC_NO_INLINE static GType
geary_mime_data_format_encoding_get_type_once (void)
{
	static const GEnumValue values[] = {{GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_REQUIRED, "GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_REQUIRED", "quoting-required"}, {GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_OPTIONAL, "GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_OPTIONAL", "quoting-optional"}, {GEARY_MIME_DATA_FORMAT_ENCODING_UNALLOWED, "GEARY_MIME_DATA_FORMAT_ENCODING_UNALLOWED", "unallowed"}, {0, NULL, NULL}};
	GType geary_mime_data_format_encoding_type_id;
	geary_mime_data_format_encoding_type_id = g_enum_register_static ("GearyMimeDataFormatEncoding", values);
	return geary_mime_data_format_encoding_type_id;
}

GType
geary_mime_data_format_encoding_get_type (void)
{
	static gsize geary_mime_data_format_encoding_type_id__once = 0;
	if (g_once_init_enter (&geary_mime_data_format_encoding_type_id__once)) {
		GType geary_mime_data_format_encoding_type_id;
		geary_mime_data_format_encoding_type_id = geary_mime_data_format_encoding_get_type_once ();
		g_once_init_leave (&geary_mime_data_format_encoding_type_id__once, geary_mime_data_format_encoding_type_id);
	}
	return geary_mime_data_format_encoding_type_id__once;
}

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 gboolean
_vala_char_array_contains (gchar * stack,
                           gssize stack_length,
                           const gchar needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (needle == stack[i]) {
			return TRUE;
		}
	}
	return FALSE;
}

GearyMimeDataFormatEncoding
geary_mime_data_format_get_encoding_requirement (const gchar* str)
{
	GearyMimeDataFormatEncoding encoding = 0;
	gint index = 0;
	GearyMimeDataFormatEncoding result;
	g_return_val_if_fail (str != NULL, 0);
	if (geary_string_is_empty (str)) {
		result = GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_REQUIRED;
		return result;
	}
	encoding = GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_OPTIONAL;
	index = 0;
	{
		gboolean _tmp0_ = FALSE;
		_tmp0_ = TRUE;
		while (TRUE) {
			gchar ch = '\0';
			const gchar* _tmp1_;
			gint _tmp2_;
			gboolean _tmp3_ = FALSE;
			if (!_tmp0_) {
			}
			_tmp0_ = FALSE;
			_tmp1_ = str;
			_tmp2_ = index;
			index = _tmp2_ + 1;
			ch = string_get (_tmp1_, (glong) _tmp2_);
			if (ch == GEARY_STRING_EOS) {
				break;
			}
			if (g_ascii_iscntrl (ch)) {
				result = GEARY_MIME_DATA_FORMAT_ENCODING_UNALLOWED;
				return result;
			}
			if (g_ascii_isspace (ch)) {
				_tmp3_ = TRUE;
			} else {
				_tmp3_ = _vala_char_array_contains (GEARY_MIME_DATA_FORMAT_CONTENT_TYPE_TOKEN_SPECIALS, G_N_ELEMENTS (GEARY_MIME_DATA_FORMAT_CONTENT_TYPE_TOKEN_SPECIALS), ch);
			}
			if (_tmp3_) {
				encoding = GEARY_MIME_DATA_FORMAT_ENCODING_QUOTING_REQUIRED;
			}
		}
	}
	result = encoding;
	return result;
}

