-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
35 lines (32 loc) · 1.37 KB
/
ft_strtrim.c
File metadata and controls
35 lines (32 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strtrim.c :+: :+: */
/* +:+ */
/* By: cwesseli <cwesseli@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/10/13 09:48:20 by cwesseli #+# #+# */
/* Updated: 2022/10/18 13:39:21 by cwesseli ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
unsigned int start;
unsigned int end;
unsigned int len_ret;
char *ret;
start = 0;
end = ft_strlen(s1);
if (!s1)
return (NULL);
if (!set || *set == '\0' || *s1 == '\0')
return (ft_strdup((char *)s1));
while (ft_strchr(set, s1[start]) && s1[start])
start++;
while (ft_strchr(set, s1[end - 1]) && s1[end - 1] && end > start)
end--;
len_ret = end - start;
ret = (ft_substr(s1, start, len_ret));
return (ret);
}