-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
40 lines (36 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysaito <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/29 00:23:02 by ysaito #+# #+# */
/* Updated: 2021/11/01 20:58:07 by ysaito ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t judge_trim(char c, char const *set)
{
while (*set)
{
if (c == *set)
return (1);
set++;
}
return (0);
}
char *ft_strtrim(char const *s1, char const *set)
{
int start;
int end;
if (s1 == NULL || set == NULL)
return (NULL);
start = 0;
while (s1[start] != '\0' && judge_trim(s1[start], set))
start++;
end = ft_strlen(s1);
while (end > start && judge_trim(s1[end - 1], set))
end--;
return (ft_substr((char *)s1, start, end - start));
}