-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
31 lines (28 loc) · 1.21 KB
/
ft_strtrim.c
File metadata and controls
31 lines (28 loc) · 1.21 KB
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: nsterk <nsterk@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/10/29 21:10:11 by nsterk #+# #+# */
/* Updated: 2021/03/03 01:45:43 by nsterk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *rstr;
size_t end;
if (!s1)
return (NULL);
if (s1 != 0 && !set)
return (ft_strdup(s1));
while (*s1 && ft_strchr(set, *s1))
s1++;
end = ft_strlen(s1);
while (end && ft_strchr(set, s1[end]))
end--;
rstr = ft_substr(s1, 0, end + 1);
return (rstr);
}