-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
41 lines (38 loc) · 1.28 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
32
33
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahel-bah <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/12 14:48:35 by ahel-bah #+# #+# */
/* Updated: 2021/11/17 18:02:33 by ahel-bah ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *ml;
int i;
int j;
if (!s1 || !set)
return (0);
i = 0;
while (s1[i] != '\0')
{
if (ft_strchr(set, s1[i]) == 0)
break ;
i++;
}
j = ft_strlen(s1);
while (j >= 0 && ft_strlen(set) > 0)
{
if (ft_strrchr(set, s1[j]) == 0)
break ;
j--;
}
ml = ft_substr(s1, i, j + 1 - i);
if (ml == 0)
return (0);
return (ml);
}