-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
50 lines (46 loc) · 1.48 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rabougue <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/03 10:34:14 by rabougue #+# #+# */
/* Updated: 2016/05/04 09:19:49 by rabougue ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/libft.h"
static void skip_blank(const char *s, int *i, int *len)
{
while (s[*i] != '\0')
{
if (s[*i] != ' ' && s[*i] != '\n' && s[*i] != '\t')
{
*i += 1;
*len = *i;
}
else
*i += 1;
}
}
char *ft_strtrim(char const *s)
{
char *str;
int start;
int len;
int i;
if (s == NULL)
return (0);
start = 0;
len = 0;
i = 0;
while (s[start] == ' ' || s[start] == '\n' || s[start] == '\t')
start++;
skip_blank(s, &i, &len);
if (i == 0 || ft_strsub(s, start, len - start) == NULL)
{
str = ft_strdup("");
return (str);
}
return (ft_strsub(s, start, len - start));
}