-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
27 lines (24 loc) · 1.14 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: nopereir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/20 22:55:39 by nopereir #+# #+# */
/* Updated: 2022/06/28 14:43:18 by nopereir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
if (s1 == NULL || set == NULL)
return (NULL);
while (ft_strchr(set, *s1) && *s1)
s1++;
i = ft_strlen(s1);
while (ft_strchr(set, s1[i - 1]) && i)
i--;
return (ft_substr(s1, 0, i));
}