-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
33 lines (30 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dapetros <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/24 21:00:40 by dapetros #+# #+# */
/* Updated: 2024/01/25 14:46:49 by dapetros ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t start;
size_t end;
size_t s1_len;
char *str;
if (!s1 || !set)
return (NULL);
start = 0;
s1_len = ft_strlen(s1);
while (ft_strchr(set, s1[start]) && s1[start])
++start;
end = s1_len - 1;
while (ft_strchr(set, s1[end]) && end >= start)
--end;
str = ft_substr(s1, start, end - start + 1);
return (str);
}