-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
30 lines (26 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zkharbac <zkharbac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/28 15:15:50 by zkharbac #+# #+# */
/* Updated: 2024/11/29 10:44:00 by zkharbac ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(const char *s1, const char *set)
{
size_t start;
size_t end;
if (!s1 || !set)
return (NULL);
start = 0;
end = ft_strlen(s1);
while (s1[start] && ft_strchr(set, s1[start]))
start++;
while (end > start && ft_strchr(set, s1[end - 1]))
end--;
return (ft_substr(s1, start, end - start));
}