-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
44 lines (40 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
41
42
43
44
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hnabil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/22 21:59:37 by hnabil #+# #+# */
/* Updated: 2019/10/25 20:10:27 by hnabil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_exist(const char *str, const char c)
{
while (*str)
{
if (*str == c)
return (1);
str++;
}
return (0);
}
char *ft_strtrim(char const *s1, char const *set)
{
char *res;
size_t len;
unsigned int i;
if (!s1 || !set)
return (0);
i = 0;
len = ft_strlen(s1);
while (ft_exist(set, s1[i]) && i < len)
i++;
if (i == len)
return (ft_strdup(""));
while (ft_exist(set, s1[--len]))
;
res = ft_substr(s1, i, len - i + 1);
return (res);
}