diff options
Diffstat (limited to 'libft/src/str/ft_strtrim.c')
| -rw-r--r-- | libft/src/str/ft_strtrim.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libft/src/str/ft_strtrim.c b/libft/src/str/ft_strtrim.c new file mode 100644 index 0000000..fa9b192 --- /dev/null +++ b/libft/src/str/ft_strtrim.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:24:16 by cacharle #+# #+# */ +/* Updated: 2020/04/05 13:50:43 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t start; + size_t len; + + if (s1 == NULL || set == NULL) + return (NULL); + start = 0; + while (s1[start] && ft_strchr(set, s1[start]) != NULL) + start++; + len = ft_strlen(&s1[start]); + if (len != 0) + while (s1[start + len - 1] + && ft_strchr(set, s1[start + len - 1]) != NULL) + len--; + return (ft_strsub(s1, start, len)); +} |
