-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
31 lines (28 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lenzo-pe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/01 22:21:22 by lenzo-pe #+# #+# */
/* Updated: 2021/08/01 22:21:23 by lenzo-pe ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *ptr;
size_t len;
if (!s1 || !set)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;
len = ft_strlen(s1);
while (len && ft_strchr(set, s1[len]))
len--;
ptr = ft_substr(s1, 0, len + 1);
if (!ptr)
return (NULL);
return (ptr);
}