/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strtrim.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: scebula +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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))); }