-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
37 lines (34 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfreitas <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/21 16:35:13 by jfreitas #+# #+# */
/* Updated: 2019/11/21 11:58:21 by jfreitas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
int start;
int len;
char *str;
if (s1)
{
start = 0;
while (s1[start] && ft_strchr(set, s1[start]) != NULL)
start++;
len = ft_strlen(&s1[start]);
if (len != 0)
while (s1[start + len - 1] &&
ft_strchr(set, s1[start + len - 1]) != NULL)
len--;
str = ft_substr(s1, start, len);
if (s1 == NULL || str == NULL || set == NULL)
return (NULL);
return (str);
}
return (0);
}