-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_strtrim.c
35 lines (32 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abello-r <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/14 10:49:49 by abello-r #+# #+# */
/* Updated: 2020/01/14 18:53:27 by abello-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t len;
char *x;
if (!s1 || !set)
return (NULL);
while (ft_strchr(set, *s1) && *s1 != '\0')
{
s1++;
}
if (*s1 == '\0')
return (ft_strdup(""));
len = ft_strlen(s1);
while (ft_strchr(set, s1[len]))
{
len--;
}
x = ft_substr(s1, 0, len + 1);
return (x);
}