char	*ft_tild(t_printf *info, int *lenght)
{
	int		len;
	char	*space;

	space = localeconv()->decimal_point;
	len = ft_strlen(info->value) - ft_len_untill(info->value, '.');
	if (info->tild && ft_strchr("fF", info->type) && info->type)
		while (len > 3)
		{
			if (len + ft_len_untill(info->value, '.') != ft_strlen(info->value))
				info->value = ft_strinsert(info->value,
					space, len + ft_len_untill(info->value, '.'));
			len -= 3;
			(*lenght) += 1;
		}
	len = ft_len_untill(info->value, '.');
	if (info->tild && ft_strchr("duifF", info->type) && info->type)
		while (len > 3)
		{
			info->value = ft_strinsert(info->value, space, len - 3);
			len -= 3;
			(*lenght) += 1;
		}
	if (info->intero && ++(*lenght))
		info->value = ft_strjoinnchar(info->value, -1, info->type);
	return (info->value);
}
Example #2
0
char	*ft_strnreplace(char *str, char *match, char *to, size_t nbr)
{
	size_t	pos;
	int		len;
	char	*last;
	char	*tmp;

	last = NULL;
	if (!str || !match || !to)
		return (str);
	while (str != last && (last = str) && nbr--)
	{
		if ((tmp = ft_strstr(str, match)))
		{
			pos = (size_t)(tmp - str);
			if (pos < ft_strlen(str))
			{
				len = ft_strlen(match);
				ft_memmove(str + pos, str + pos + len,
						ft_strlen(str + pos + len) + 1);
				str = ft_strinsert(str, to, pos);
			}
		}
	}
	return (str);
}
Example #3
0
void	insert_key(char *key, char **line, int *pos)
{
	*line = ft_strinsert(*line, *key, term_line_index(pos, line));
	if ((pos[1] ? pos[0] + 1 : pos[0] + PROMPTLEN) == tgetnum("co"))
	{
		pos[1]++;
		pos[0] = -1;
		ft_putendl("");
	}
	pos[0]++;
	tputs(tgetstr("im", NULL), 0, ft_outc);
	tputs(tgetstr("ic", NULL), 0, ft_outc);
	ft_outc(*key);
	tputs(tgetstr("ip", NULL), 0, ft_outc);
	tputs(tgetstr("ei", NULL), 0, ft_outc);
	if (term_line_index(pos, line) < (int)ft_strlen(*line))
	{
		tputs(tgetstr("sc", NULL), 0, ft_outc);
		ft_putstr(*line + term_line_index(pos, line));
		tputs(tgetstr("rc", NULL), 0, ft_outc);
	}
}