-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
34 lines (31 loc) · 1.26 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
34
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adashyan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 22:39:44 by adashyan #+# #+# */
/* Updated: 2022/05/08 18:31:07 by adashyan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
char *ft_strtrim(char const *s, char const *set)
{
size_t i;
size_t j;
char *trim;
i = 0;
if (s == NULL || set == NULL)
return (NULL);
j = ft_strlen(s);
while (s[i] != '\0' && ft_strchr(set, s[i]))
i++;
while (s[j - 1] && ft_strchr(set, s[j - 1]) && j > i)
j--;
trim = ft_substr(s, i, j - i);
if (!trim)
return (NULL);
return (trim);
}