-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
46 lines (41 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vscabell <vscabell@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/22 17:33:10 by vscabell #+# #+# */
/* Updated: 2020/06/09 18:29:27 by vscabell ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_isset(char c, char const *set)
{
int i;
i = 0;
while (set[i])
if (c == set[i++])
return (1);
return (0);
}
char *ft_strtrim(char const *s1, char const *set)
{
size_t len;
char *ptr;
size_t i;
size_t j;
if (!s1)
return (NULL);
len = ft_strlen(s1);
i = 0;
while (ft_isset(s1[i], set))
i++;
if (i == len)
return (ft_strdup(""));
j = ft_strlen(s1) - 1;
while (ft_isset(s1[j], set))
j--;
ptr = ft_substr(s1, i, j - i + 1);
return (ptr);
}