37 lines
1.3 KiB
C
37 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strtrim.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: scebula <scebula@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2015/11/26 11:03:36 by scebula #+# #+# */
|
|
/* Updated: 2015/12/03 22:45:16 by scebula ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strtrim(char const *s)
|
|
{
|
|
size_t i;
|
|
unsigned int begin;
|
|
unsigned int end;
|
|
|
|
i = 0;
|
|
begin = 0;
|
|
end = 0;
|
|
while (s[i] && (s[i] == ' ' || s[i] == '\t' || s[i] == '\n'))
|
|
i++;
|
|
if (s[i] == '\0')
|
|
return (ft_strnew(0));
|
|
begin = i;
|
|
while (s[i])
|
|
{
|
|
if (s[i] != ' ' && s[i] != '\t' && s[i] != '\n')
|
|
end = i;
|
|
i++;
|
|
}
|
|
return (ft_strsub(s, begin, (size_t)(end - begin + 1)));
|
|
}
|