-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
33 lines (30 loc) · 1.21 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
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajakob <ajakob@student.42heilbronn.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/20 22:19:06 by ajakob #+# #+# */
/* Updated: 2022/11/30 15:06:44 by ajakob ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *str;
size_t i;
size_t j;
if (!set)
return (NULL);
if (!*s1)
return (ft_strdup(""));
i = 0;
while (s1[i] && ft_strchr(set, s1[i]))
i++;
j = ft_strlen(s1) - 1;
while (j && ft_strchr(set, s1[j]))
j--;
str = ft_substr(s1, i, j - i + 1);
return (str);
}