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

/*
 * Copyright (C) 2013-2017 elementary Developers
 *
 * 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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

VALA_EXTERN gboolean contractor_string_is_empty (const gchar* str);
VALA_EXTERN GList* contractor_string_array_to_list (gchar** array,
                                        gint array_length1);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
VALA_EXTERN gchar** contractor_string_clean_array (gchar** str_array,
                                       gint str_array_length1,
                                       gint* result_length1);

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

gboolean
contractor_string_is_empty (const gchar* str)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if (str == NULL) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = string_strip (str);
		_tmp2_ = _tmp1_;
		_tmp0_ = g_strcmp0 (_tmp2_, "") == 0;
		_g_free0 (_tmp2_);
	}
	result = _tmp0_;
	return result;
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

GList*
contractor_string_array_to_list (gchar** array,
                                 gint array_length1)
{
	GList* list = NULL;
	gboolean _tmp0_ = FALSE;
	GList* result;
	list = NULL;
	if (array != NULL) {
		_tmp0_ = array_length1 > 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		(list == NULL) ? NULL : (list = (_g_list_free__g_free0_ (list), NULL));
		list = NULL;
		{
			gchar** str_collection = NULL;
			gint str_collection_length1 = 0;
			gint _str_collection_size_ = 0;
			gint str_it = 0;
			str_collection = array;
			str_collection_length1 = array_length1;
			for (str_it = 0; str_it < str_collection_length1; str_it = str_it + 1) {
				gchar* _tmp1_;
				gchar* str = NULL;
				_tmp1_ = g_strdup (str_collection[str_it]);
				str = _tmp1_;
				{
					const gchar* _tmp2_;
					gchar* _tmp3_;
					_tmp2_ = str;
					_tmp3_ = g_strdup (_tmp2_);
					list = g_list_prepend (list, _tmp3_);
					_g_free0 (str);
				}
			}
		}
		list = g_list_reverse (list);
	}
	result = list;
	return result;
}

/**
     * Removes duplicate and empty strings from the given array.
     */
gchar**
contractor_string_clean_array (gchar** str_array,
                               gint str_array_length1,
                               gint* result_length1)
{
	GeeHashSet* container = NULL;
	GeeHashSet* _tmp0_;
	GeeHashSet* _tmp11_;
	gint _tmp12_ = 0;
	gpointer* _tmp13_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	gchar** result;
	_tmp0_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
	container = _tmp0_;
	{
		gchar** str_collection = NULL;
		gint str_collection_length1 = 0;
		gint _str_collection_size_ = 0;
		gint str_it = 0;
		str_collection = str_array;
		str_collection_length1 = str_array_length1;
		for (str_it = 0; str_it < str_collection_length1; str_it = str_it + 1) {
			gchar* _tmp1_;
			gchar* str = NULL;
			_tmp1_ = g_strdup (str_collection[str_it]);
			str = _tmp1_;
			{
				const gchar* _tmp2_;
				_tmp2_ = str;
				if (_tmp2_ != NULL) {
					gchar* clean_str = NULL;
					const gchar* _tmp3_;
					gchar* _tmp4_;
					gboolean _tmp5_ = FALSE;
					const gchar* _tmp6_;
					_tmp3_ = str;
					_tmp4_ = string_strip (_tmp3_);
					clean_str = _tmp4_;
					_tmp6_ = clean_str;
					if (g_strcmp0 (_tmp6_, "") != 0) {
						GeeHashSet* _tmp7_;
						const gchar* _tmp8_;
						_tmp7_ = container;
						_tmp8_ = clean_str;
						_tmp5_ = !gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp7_, _tmp8_);
					} else {
						_tmp5_ = FALSE;
					}
					if (_tmp5_) {
						GeeHashSet* _tmp9_;
						const gchar* _tmp10_;
						_tmp9_ = container;
						_tmp10_ = clean_str;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp9_, _tmp10_);
					}
					_g_free0 (clean_str);
				}
				_g_free0 (str);
			}
		}
	}
	_tmp11_ = container;
	_tmp13_ = gee_collection_to_array ((GeeCollection*) _tmp11_, &_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp14__length1 = _tmp12_;
	if (result_length1) {
		*result_length1 = _tmp14__length1;
	}
	result = _tmp14_;
	_g_object_unref0 (container);
	return result;
}

