示例#1
0
char		*ft_strtrim(char const *s)
{
	char	*res;
	int		start;
	int		end;
	int		i;

	start = 0;
	while (s && ft_is_space(s[start]))
		start++;
	end = ft_strlen(s) - 1;
	while (s && ft_is_space(s[end]) && end >= start)
		end--;
	res = (char *)malloc((end - start + 2) * sizeof(*res));
	if (res && s && end != 0)
	{
		i = 0;
		while ((i + start) <= end)
		{
			res[i] = s[start + i];
			i++;
		}
		res[i] = 0;
		return (res);
	}
	return (NULL);
}
示例#2
0
int				ft_atoi_base(const char *str, int base)
{
	int	i;
	int	sign;

	i = -1;
	sign = 1;
	if (base > 0 && base < 17)
	{
		if (!ft_strncmp(str, "0x", 2) || !ft_strncmp(str, "0X", 2))
			i += 2;
		while (str[++i])
		{
			if (ft_ishexa(str[i]))
				return (sign * ft_calc(str, i, base));
			if (str[i] == '-' || str[i] == '+')
			{
				if (!ft_ishexa(str[i + 1]))
					return (0);
				sign = 44 - str[i];
			}
			else if (!ft_is_space(str[i]))
				return (0);
		}
	}
	return (0);
}
示例#3
0
static int		ft_sp(char c)
{
	return (ft_is_space(c) || ft_is_other(c));
}