Example #1
0
char		*ft_strtrim(char const *s)
{
	char	*ret;
	size_t	i;
	size_t	j;

	i = 0;
	j = 0;
	if (s == NULL)
		return (NULL);
	if (!(ret = ft_strnew(ft_strlen(s) + 1)))
		return (NULL);
	while (ft_iswhitespace(s[i]))
		i++;
	while (s[i])
	{
		ret[j] = s[i];
		i++;
		j++;
	}
	ret[j--] = '\0';
	while (ft_iswhitespace(ret[j]))
		ret[j--] = '\0';
	return (ret);
}
Example #2
0
static void	move_cursor_word_left(t_env *e, char *str)
{
	int		j;
	int		blank;

	j = 0;
	blank = ft_iswhitespace(str[e->curs_pos]);
	while (e->curs_pos >= 0)
	{
		if (ft_iswhitespace(str[e->curs_pos]) != blank || e->curs_pos == 0)
		{
			e->curs_pos++;
			go_to_position(e, str, e->curs_pos);
			break ;
		}
		e->curs_pos--;
		j++;
	}
}
Example #3
0
static void	move_cursor_word_right(t_env *e, char *str)
{
	int		j;
	int		blank;

	j = 0;
	blank = ft_iswhitespace(str[e->curs_pos]);
	while (e->curs_pos <= e->curs_max)
	{
		if (ft_iswhitespace(str[e->curs_pos]) != blank ||
				e->curs_pos == e->curs_max)
		{
			go_to_position(e, str, e->curs_pos);
			break ;
		}
		e->curs_pos++;
		j++;
	}
}
Example #4
0
char		*ft_strtrim(char const *s)
{
	int		len;
	int		endchar;
	int		startchar;

	if (!s)
		return (NULL);
	endchar = 0;
	startchar = 0;
	len = ft_strlen(s);
	while (ft_iswhitespace(s[len - 1 - endchar]))
		endchar++;
	while (ft_iswhitespace(s[startchar]))
		startchar++;
	if ((len - startchar - endchar) <= 0)
		return (ft_strnew(0));
	return (ft_strsub(s, startchar, (size_t)(len - startchar - endchar)));
}
Example #5
0
char		*ft_strtrim(const char *s)
{
	size_t	i;
	size_t	lenght;
	char	*result;

	if (!s)
		return (NULL);
	i = 0;
	lenght = ft_strlen(s);
	while (ft_iswhitespace(s[i]) && s[i] != '\0')
		i++;
	if ((s[i]) == '\0')
		return (ft_strdup(""));
	while (ft_iswhitespace(s[lenght - 1]))
		lenght--;
	lenght -= i;
	result = ft_strnew(lenght);
	if (result && lenght > 1)
		result = ft_strsub(s, (unsigned int)i, lenght);
	return (result);
}
Example #6
0
int	ft_atoi(const char *str)
{
	int		nbr;
	char	neg;

	while (ft_iswhitespace(*str))
		str++;
	neg = (*str == '-');
	if (*str == '-' || *str == '+')
		str++;
	nbr = 0;
	while (ft_isdigit(*str))
	{
		nbr = nbr * 10 + (*str - '0');
		str++;
	}
	return (neg ? -nbr : nbr);
}
char	*ft_rtrim(const char *str)
{
	char	*tmp;
	int		i;
	int		end;

	end = ft_strlen((char*)str);
	while (ft_iswhitespace(str[end]))
		end--;
	end++;
	tmp = (char*)malloc(sizeof(char) * (end));
	i = 0;
	while (i < end)
	{
		tmp[i] = str[i];
		i++;
	}
	return (tmp);
}
Example #8
0
char	*ft_strcapitalize(char *s)
{
    int i;

    i = 1;
    if (s)
    {
        ft_strtodowncase(s);
        s[0] = ft_toupper(s[0]);
        while (s[i])
        {
            if (ft_iswhitespace(s[i - 1]))
                s[i] = ft_toupper(s[i]);
            else
                s[i] = ft_tolower(s[i]);
            i++;
        }
    }
    return (s);
}
Example #9
0
long int		ft_strtol(const char *nptr, char **endptr)
{
	char	sign;

	*endptr = (char *)nptr;
	while (ft_iswhitespace(**endptr))
		++(*endptr);
	if (!ft_isdigit(**endptr) && **endptr != '-' && **endptr != '+')
		*endptr = (char *)nptr;
	else
	{
		sign = 1;
		if (**endptr == '-' || **endptr == '+')
		{
			if (**endptr == '-')
				sign = -1;
			++(*endptr);
		}
		return (ft_strtol_sub(nptr, endptr, sign));
	}
	return (0);
}
Example #10
0
int		ft_atoi(const char *str)
{
	int		result;
	int		operator;

	result = 0;
	operator = 1;
	while (ft_iswhitespace(*str))
		str++;
	if (*str == '+' || *str == '-')
	{
		if (*str == '-')
			operator = -1;
		str++;
	}
	while (ft_isdigit(*str))
	{
		result = result * 10 + operator * (*str - '0');
		str++;
	}
	return (result);
}
char	*ft_ltrim(const char *str)
{
	char	*tmp;
	int		start;
	int		end;
	int		i;
	int		k;

	start = 0;
	while (ft_iswhitespace(str[start]))
		start++;
	end = ft_strlen((char*)str);
	tmp = (char*)malloc(sizeof(char) * (end - start));
	i = 0;
	k = start;
	while (start < end)
	{
		tmp[i] = str[k];
		i++;
		k++;
	}
	return (tmp);
}