/*
 * Copyright (C) 2023-2025 Birb Developers
 *
 * Birb is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed
 * with this source distribution
 *
 * 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 2 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 <https://www.gnu.org/licenses/>.
 */

#if !defined(BIRB_GLOBAL_HEADER_INSIDE) && !defined(BIRB_COMPILATION)
# error "only <birb.h> may be included directly"
#endif

#ifndef BIRB_STR_H
#define BIRB_STR_H

#include <glib.h>

#include "birbversion.h"

G_BEGIN_DECLS

/**
 * birb_str_is_empty:
 * @str: (nullable): the string to check
 *
 * Determines if @str is empty or not.
 *
 * Returns: true if @str is empty; false otherwise.
 *
 * Since: 0.4
 */
BIRB_AVAILABLE_STATIC_INLINE_IN_0_4
static inline gboolean
birb_str_is_empty(const char *str) {
	return (str == NULL || str[0] == '\0');
}

/**
 * birb_str_equal:
 * @str1: (nullable): the first string
 * @str2: (nullable): the second string
 *
 * Checks if @str1 is equal to @str2.
 *
 * Returns: true if the strings are equal; false otherwise.
 *
 * Since: 0.4
 */
BIRB_AVAILABLE_STATIC_INLINE_IN_0_4
static inline gboolean
birb_str_equal(const char *str1, const char *str2) {
	return (g_strcmp0(str1, str2) == 0);
}

/**
 * birb_str_to_uint:
 * @str: (nullable): a string to convert to an unsigned integer
 *
 * Converts @str to an unsigned integer.
 *
 * Returns: The converted value or 0 on error.
 *
 * Since: 0.4
 */
BIRB_AVAILABLE_STATIC_INLINE_IN_0_4
static inline guint
birb_str_to_uint(const char *str) {
	int ivalue;

	if(birb_str_is_empty(str)) {
		return 0;
	}

	ivalue = atoi(str);

	return (guint)ivalue;
}

G_END_DECLS

#endif /* BIRB_STR_H */
