-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_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: hbaddrul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/07 15:58:24 by hbaddrul #+# #+# */
/* Updated: 2021/07/30 16:31:21 by hbaddrul ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include "libft.h"
static int ft_isset(char c, const char *set)
{
while (*set)
if (c == *set++)
return (1);
return (0);
}
char *ft_strtrim(const char *s1, const char *set)
{
char *ret;
char *start;
char *end;
if (!s1 || !set)
return (0);
start = (char *)s1;
end = start + ft_strlen(s1);
while (*start && ft_isset(*start, set))
++start;
while (start < end && ft_isset(*(end - 1), set))
--end;
ret = ft_substr(start, 0, end - start);
return (ret);
}