-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strtrim.c
29 lines (26 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlambert <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/05 15:11:42 by rlambert #+# #+# */
/* Updated: 2015/01/02 16:21:42 by rlambert ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char const *s_end;
if (s == NULL)
return (NULL);
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
if (*s == '\0')
return (ft_strnew(0));
s_end = s + ft_strlen(s) - 1;
while (*s_end == ' ' || *s_end == '\t' || *s_end == '\n')
s_end--;
return (ft_strsub(s, 0, s_end - s + 1));
}