-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
40 lines (36 loc) · 1.32 KB
/
ft_strtrim.c
File metadata and controls
40 lines (36 loc) · 1.32 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
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mjusta <mjusta@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/28 00:36:02 by mjusta #+# #+# */
/* Updated: 2025/05/28 11:37:11 by mjusta ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_in_set(char c, const char *set)
{
while (*set)
{
if (*set == c)
return (1);
set++;
}
return (0);
}
char *ft_strtrim(char const *s1, char const *set)
{
size_t start;
size_t end;
if (!s1 || !set)
return (NULL);
start = 0;
while (s1[start] && is_in_set(s1[start], set))
start++;
end = ft_strlen(s1);
while (end > start && is_in_set(s1[end - 1], set))
end--;
return (ft_substr(s1, start, end - start));
}