-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strtrim.c
32 lines (29 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <me@izenynn.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/17 17:47:56 by dpoveda- #+# #+# */
/* Updated: 2023/03/13 17:29:06 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/ft_str.h"
char *ft_strtrim(const char *s1, const char *set)
{
char *res;
size_t len;
if (!s1)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;
len = ft_strlen(s1);
while (len > 0 && ft_strchr(set, s1[len - 1]))
len--;
res = malloc(len + 1);
if (!res)
return (NULL);
ft_strlcpy(res, s1, len + 1);
return (res);
}