-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
40 lines (37 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yshimoda <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/06 11:14:10 by yshimoda #+# #+# */
/* Updated: 2022/10/20 21:40:22 by yshimoda ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char const *head;
char const *tail;
char *str;
if (!s1)
return (NULL);
head = s1;
tail = s1 + ft_strlen(s1) - 1;
while (*head)
{
if (!ft_strchr(set, *head))
break ;
head++;
}
while (head < tail)
{
if (!ft_strchr(set, *tail))
break ;
tail--;
}
tail++;
str = ft_substr(head, 0, tail - head);
return (str);
}