-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
53 lines (48 loc) · 1.43 KB
/
ft_strtrim.c
File metadata and controls
53 lines (48 loc) · 1.43 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
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strtrim.c :+: :+: */
/* +:+ */
/* By: ivork <ivork@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/07 19:57:53 by ivork #+# #+# */
/* Updated: 2021/10/12 17:47:33 by ivork ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_in_set(char c, const char *set)
{
int i;
i = 0;
while (set[i] != 0)
{
if (set[i] == c)
return (1);
i++;
}
return (0);
}
char *ft_strtrim(char const *s1, char const *set)
{
char *newstr;
int start;
int end;
start = 0;
if (!s1 || !set)
return (NULL);
while (s1[start] != '\0')
{
if (!(is_in_set(s1[start], set)))
break ;
start++;
}
end = ft_strlen(s1);
while (end - 1 > start)
{
if (!(is_in_set(s1[end - 1], set)))
break ;
end--;
}
newstr = ft_substr(s1, start, end - start);
return (newstr);
}