-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
34 lines (30 loc) · 1.39 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: bnidia <bnidia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/17 14:40:04 by bnidia #+# #+# */
/* Updated: 2021/10/25 19:48:25 by bnidia ### ########.fr */
/* */
/* ************************************************************************** */
/* ft_strtrim
** Allocates (with malloc) and returns a copy of 's1' with the characters
** specified in 'set' removed from the beginning and the end of the string
** Return Value
** The trimmed string. NULL if the allocation fails
*/
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t s1_len;
if (!s1 || !set)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;
s1_len = ft_strlen(s1);
while (s1_len && ft_strchr(set, s1[s1_len]))
s1_len--;
return (ft_substr(s1, 0, s1_len + 1));
}