-
Notifications
You must be signed in to change notification settings - Fork 4
/
ft_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: ykoh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:29:28 by ykoh #+# #+# */
/* Updated: 2020/05/05 00:48:01 by ykoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *rear;
if (!s1 || !set)
return (NULL);
while (*s1)
{
if (!(ft_strchr(set, *s1)))
break ;
s1++;
}
rear = (char *)s1 + (ft_strlen(s1) - 1);
while (rear >= s1)
{
if (!(ft_strchr(set, *rear)))
break ;
rear--;
}
return (ft_strndup(s1, ++rear - s1));
}