-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
27 lines (24 loc) · 1.15 KB
/
ft_strtrim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anhigo-s <anhigo-s@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/01 22:17:51 by anhigo-s #+# #+# */
/* Updated: 2023/02/23 17:35:05 by anhigo-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t end;
if (!s1 || !set)
return (NULL);
while (*s1 != '\0' && (ft_strchr(set, *s1)))
s1++;
end = ft_strlen(s1);
while (end && ft_strchr(set, s1[end]))
end--;
return (ft_substr(s1, 0, end + 1));
}