-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
52 lines (46 loc) · 1.49 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
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erlajoua <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/17 12:03:45 by erlajoua #+# #+# */
/* Updated: 2020/11/17 12:03:46 by erlajoua ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isset(char *str, char *wrong)
{
while (*wrong)
{
if (*wrong == *str)
return (1);
wrong++;
}
return (0);
}
char *count_malloc(char *str, char *wrong)
{
int full_size;
int i;
i = 0;
while (ft_isset(&str[i], wrong))
i++;
full_size = ft_strlen(str);
while (ft_isset(&str[full_size - 1], wrong))
full_size--;
if (full_size < i)
full_size = i;
return (ft_substr(str, i, full_size - i));
}
char *ft_strtrim(char const *s1, char const *set)
{
char *str;
char *wrong;
if (!s1 || !set)
return (NULL);
str = (char *)s1;
wrong = (char *)set;
return (count_malloc(str, wrong));
}