-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
31 lines (28 loc) · 1.21 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
28
29
30
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/09 18:14:41 by earnaud #+# #+# */
/* Updated: 2020/11/11 18:53:52 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
size_t j;
char *result;
j = ft_strlen(s1);
i = 0;
if (!s1 || !set)
return (0);
while (s1[i] && ft_strchr((char *)set, s1[i]))
i++;
while (j && j > i && ft_strchr((char *)set, s1[j]))
j--;
result = ft_substr(s1, i, j - i + 1);
return (result);
}