-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
47 lines (41 loc) · 1.38 KB
/
ft_strtrim.c
File metadata and controls
47 lines (41 loc) · 1.38 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
41
42
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: musajid <musajid@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/11 23:04:16 by musajid #+# #+# */
/* Updated: 2025/05/23 19:11:55 by musajid ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int to_trim(const char *set, char c);
char *ft_strtrim(const char *s1, const char *set)
{
size_t i;
size_t j;
i = 0;
if (!s1 || !set)
return (NULL);
j = ft_strlen(s1) - 1;
if (ft_strlen(s1) == 0)
return (ft_strdup(""));
while (to_trim(set, s1[i]))
i++;
while (to_trim(set, s1[j]))
j--;
return (ft_substr(s1, i, j - (i - 1)));
}
static int to_trim(const char *set, char c)
{
int i;
i = 0;
while (set[i])
{
if (c == set[i])
return (1);
i++;
}
return (0);
}