-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
executable file
·38 lines (34 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/14 17:24:36 by jraymond #+# #+# */
/* Updated: 2017/11/28 13:31:33 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_whiteword(char c)
{
return (c == ' ' || c == '\n' || c == '\t');
}
char *ft_strtrim(char const *s)
{
int lenght;
int start;
int end;
if (!s)
return (NULL);
start = 0;
lenght = ft_strlen(s);
end = 0;
while (s[start] && ft_whiteword(s[start]))
start++;
if (start == lenght)
return (ft_strnew(0));
while (ft_whiteword(s[lenght - end - 1]) && lenght - end - 1 > 0)
end++;
return (ft_strsub(s, start, lenght - end - start));
}