-
Notifications
You must be signed in to change notification settings - Fork 12
/
ft_strtrim.c
37 lines (33 loc) · 1.4 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
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 15:30:44 by apuchill #+# #+# */
/* Updated: 2020/02/19 14:06:54 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: N/A
** SYNOPSIS: trim beginning and end of string with the specified characters
**
** DESCRIPTION:
** Allocates (with malloc(3)) and returns a copy of ’s1’ with the
** characters specified in ’set’ removed from the beginning and the end of the
** string.
*/
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
if (!s1 || !set)
return (0);
while (*s1 && ft_strchr(set, *s1))
s1++;
i = ft_strlen(s1);
while (i && ft_strchr(set, s1[i]))
i--;
return (ft_substr(s1, 0, i + 1));
}