-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strtrim.c
47 lines (42 loc) · 1.41 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
42
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-mlil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/26 18:42:08 by sel-mlil #+# #+# */
/* Updated: 2024/10/28 06:02:16 by sel-mlil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int check(char c, char *set)
{
int i;
i = 0;
while (set[i])
{
if (set[i] == c)
return (1);
i++;
}
return (0);
}
char *ft_strtrim(char const *s1, char const *set)
{
int start;
int end;
start = 0;
if (!s1)
return (NULL);
if (!*s1)
return (ft_strdup(""));
while (s1[start] && check(s1[start], (char *)set) == 1)
start++;
end = ft_strlen(s1) - 1;
while (s1[end] && check(s1[end], (char *)set) == 1)
end--;
if (start > end)
return (ft_strdup(""));
return (ft_substr(s1, start, end - start + 1));
}