示例#1
0
static bool	uf_getopt_init_option(t_getopt *v_this, size_t ac, const char **av)
{
	size_t		i;
	size_t		size;
	t_string	string;

	i = 1;
	if (D_STRING(init)(&string, 0) == false)
		return (M_ERROR(false, "Could not initialize string"));
	while (i < ac)
	{
		size = uf_str_len(av[i]);
		if (uf_fmt_av(v_this, &string, size == 2 && av[i][0] == '-'
			&& av[i][1] != '-', av[i] + 1) == false
			|| uf_fmt_av(v_this, &string, size > 3 && av[i][0] == '-'
			&& av[i][1] == '-' && av[i][2] != '-', av[i] + 2) == false)
			break ;
		i = i + 1;
	}
	if (i == ac)
	{
		v_this->v_option = D_STRING(split)(&string, " ");
		if (v_this->v_option == NULL)
			i = 0;
	}
	D_STRING(destroy)(&string);
	return (i == ac);
}
示例#2
0
char				*uf_itoa_base(int nbr, size_t base)
{
	char		*ret;
	t_string	str;

	ret = NULL;
	if (D_STRING(init)(&str, 0) == true
		&& D_STRING(add_nbr_base)(&str, nbr, base) == true)
		ret = D_STRING(dup)(&str);
	D_STRING(destroy)(&str);
	return (ret);
}
示例#3
0
bool		f_string_add_ptr(t_string *v_this, void *addr)
{
	size_t	nbr;
	size_t	digit;
	ui		size;

	size = 1;
	digit = 1;
	nbr = (size_t)addr;
	while ((nbr / digit) >= 16)
	{
		digit = digit * 16;
		size = size + 1;
	}
	size = size + 1;
	if (v_this->v_size + size + 2 > v_this->v_capacity &&
		uf_string_realloc(v_this, size) == false)
		return (false);
	D_STRING(add_str)(v_this, "0x");
	while (digit > 0)
	{
		v_this->v_str[v_this->v_size] = v_this->v_hex[nbr / digit % 16];
		v_this->v_size = v_this->v_size + 1;
		digit = digit / 16;
	}
	v_this->v_str[v_this->v_size] = '\0';
	return (true);
}
示例#4
0
bool		f_string_add_nbr_base(t_string *v_this, ssize_t nbr, ui base)
{
	ui	size;
	ui	digit;

	digit = uf_string_get_digit(nbr, base, &size);
	if (base == 16 && D_STRING(add_str)(v_this, "0x") == false)
		return (false);
	if (v_this->v_size + size > v_this->v_capacity &&
		uf_string_realloc(v_this, size) == false)
		return (false);
	if (nbr < 0)
	{
		v_this->v_str[v_this->v_size] = '-';
		v_this->v_size = v_this->v_size + 1;
		nbr = -nbr;
	}
	while (digit > 0)
	{
		v_this->v_str[v_this->v_size] = v_this->v_hex[nbr / digit % base];
		v_this->v_size = v_this->v_size + 1;
		digit = digit / base;
	}
	v_this->v_str[v_this->v_size] = '\0';
	return (true);
}
示例#5
0
static bool	uf_fmt_av(t_getopt *v_this, t_string *string,
					bool value, const char *add)
{
	size_t	i;

	i = 0;
	if (value == true)
	{
		while (v_this->v_posibility[i] != NULL)
		{
			if (uf_strcmp(v_this->v_posibility[i], add) == 0)
			{
				if (D_STRING(add_str)(string, add) == false
					|| D_STRING(add_char)(string, ' ') == false)
					return (false);
			}
			i = i + 1;
		}
	}
	return (true);
}
示例#6
0
size_t	mf_error(char nothing, size_t ret, const char *fmt, ...)
{
	va_list		ap;
	t_string	str;

	if (fmt == NULL)
	{
		uf_print_str_fd("An internal has occured\n", 2);
		return (ret);
	}
	va_start(ap, fmt);
	D_STRING(init)(&str, 0);
	D_STRING(variadic_list)(&str, fmt, &ap);
	D_STRING(add_str)(&str, ".\033[0m\n");
	D_STRING(print_fd)(&str, 2);
	D_STRING(destroy)(&str);
	va_end(ap);
	(void)nothing;
	(void)fmt;
	return (ret);
}
示例#7
0
bool	f_string_insert(t_string *v_this, const char *insert, ui at)
{
	ui	size;

	if (at >= v_this->v_size)
		return (D_STRING(add_str)(v_this, insert));
	size = uf_str_len(insert);
	if (size == 0)
		return (true);
	if (v_this->v_size + size + 1 > v_this->v_capacity &&
		uf_string_realloc(v_this, size + 1) == false)
		return (false);
	uf_memcpy(v_this->v_str + at + size, v_this->v_str + at,
			  v_this->v_size - at);
	uf_memcpy(v_this->v_str + at, insert, size);
	v_this->v_size = v_this->v_size + size;
	return (true);
}
示例#8
0
void	D_UNIT_FUNCT(memleaks)
{
	ui			i;
	t_string	string;

	i = 0;
	D_STRING(init)(&string, 0);
	while (i < 5)
	{
		D_STRING(add_str)(&string, "hello boys");
		D_STRING(add_nbr)(&string, 42);
		D_STRING(add_ptr)(&string, &string);
		D_STRING(variadic)(&string, "%e%X", 35, 42);
		i = i + 1;
	}
	D_STRING(destroy)(&string);
	(void)t;
}
示例#9
0
static bool	uf_getopt_split_posibility(t_getopt *v_this, const char *posibility)
{
	t_string	string;

	if (D_STRING(init)(&string, 0) == false)
		return (M_ERROR(false, "Could not initialize string"));
	if (D_STRING(add_str)(&string, posibility) == false)
	{
		D_STRING(destroy)(&string);
		return (M_ERROR(false, "Could not add [%s]", posibility));
	}
	v_this->v_posibility = D_STRING(split)(&string, ":");
	if (v_this->v_posibility == NULL)
	{
		D_STRING(destroy)(&string);
		return (M_ERROR(false, "Could not split [%s]", posibility));
	}
	D_STRING(destroy)(&string);
	return (true);
}
示例#10
0
void	mf_infos(const char *funct, const char *infos, ...)
{
	va_list		ap;
	t_string	str;

	if (infos == NULL)
	{
		uf_print_str_fd("An internal has occured\n", 2);
		return ;
	}
	va_start(ap, infos);
	D_STRING(init)(&str, 0);
	D_STRING(variadic)(&str, "\033[1;37m->\t%s(): \033[0;33m", funct);
	D_STRING(variadic_list)(&str, infos, &ap);
	D_STRING(add_str)(&str, ".\033[0m\n");
	D_STRING(print_fd)(&str, 2);
	D_STRING(destroy)(&str);
	va_end(ap);
	(void)funct;
	(void)infos;
}
示例#11
0
bool		f_string_add_nbr(t_string *v_this, ssize_t nbr)
{
	return (D_STRING(add_nbr_base)(v_this, nbr, 10));
}