-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
55 lines (48 loc) · 1.94 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sperez-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/23 17:10:08 by sperez-p #+# #+# */
/* Updated: 2021/09/08 14:06:18 by sperez-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
NAME
****
ft_strtrim ---> trim a set of characters from a string
SYNOPSIS
********
#include "libft.h"
char *ft_strtrim(const char *str, char const *set)
PARAMETERS
**********
str ---> the to string to trim
start ---> the set of characters to trim
DESCRIPTION
***********
The ft_strtrim() function removes any character from the string 'set' from both
the beginning and the end of the string 's1'. It does not matter the order in which
they appear or if they appear repeated, they are trimmed as long as they are at the
beginning or at the end of the string 'str'. Whether it finds a different character
at the beginning or at the end, it stops looking for it corresponding side.
RETURN VALUE
************
- A pointer to the trimmed string.
- If any of the parameters are NULL, it returns NULL.
*/
char *ft_strtrim(const char *str, char const *set)
{
size_t end;
if (!str || !set)
return (NULL);
while (*str != '\0' && ft_strchr(set, *str))
str++;
end = ft_strlen(str);
while (end && ft_strchr(set, str[end]))
end--;
return (ft_substr(str, 0, end + 1));
}