/*
 * Ibis - IRCv3 Library
 * Copyright (C) Ibis Developers
 *
 * Ibis is the legal property of its developers, whose names are too numerous to
 * list here. Please refer to the COPYRIGHT file distributed with this source
 * distribution.
 *
 * This library 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 library 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 library; if not, see <https://www.gnu.org/licenses/>.
 */

#ifndef IBIS_STRING_H
#define IBIS_STRING_H

#include <glib.h>

#include <birb.h>

#include "ibisversion.h"

G_BEGIN_DECLS

/**
 * ibis_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.3
 */
IBIS_AVAILABLE_STATIC_INLINE_IN_0_3
static inline guint
ibis_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 /* IBIS_STRING_H */
