added argument protection
This commit is contained in:
parent
45e39d4f0e
commit
f6e6bf0680
17
ft_lstmap.c
17
ft_lstmap.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/08 19:54:31 by tmaze #+# #+# */
|
/* Created: 2018/04/08 19:54:31 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/09 09:35:00 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:31:03 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,11 +24,14 @@ t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
|||||||
t_list *new;
|
t_list *new;
|
||||||
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
if (lst->next != NULL)
|
if (lst != NULL && f != NULL)
|
||||||
ret = ft_lstmap(lst->next, f);
|
{
|
||||||
if ((new = (*f)(lst)) == NULL)
|
if (lst->next != NULL)
|
||||||
ft_lstdel(&ret, &ft_lstdelmem);
|
ret = ft_lstmap(lst->next, f);
|
||||||
else
|
if ((new = (*f)(lst)) == NULL)
|
||||||
ft_lstadd(&ret, new);
|
ft_lstdel(&ret, &ft_lstdelmem);
|
||||||
|
else
|
||||||
|
ft_lstadd(&ret, new);
|
||||||
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 22:37:44 by tmaze #+# #+# */
|
/* Created: 2018/04/07 22:37:44 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 22:41:00 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:24:26 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
void ft_putendl(char const *s)
|
void ft_putendl(char const *s)
|
||||||
{
|
{
|
||||||
ft_putstr(s);
|
if (s != NULL)
|
||||||
ft_putchar('\n');
|
{
|
||||||
|
ft_putstr(s);
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/08 13:02:13 by tmaze #+# #+# */
|
/* Created: 2018/04/08 13:02:13 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/08 13:04:25 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:27:49 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
void ft_putendl_fd(char const *s, int fd)
|
void ft_putendl_fd(char const *s, int fd)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(s, fd);
|
if (s != NULL && fd >= 0)
|
||||||
ft_putchar_fd('\n', fd);
|
{
|
||||||
|
ft_putstr_fd(s, fd);
|
||||||
|
ft_putchar_fd('\n', fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 19:13:17 by tmaze #+# #+# */
|
/* Created: 2018/04/07 19:13:17 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 19:16:28 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:20:31 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,5 +14,6 @@
|
|||||||
|
|
||||||
void ft_putstr(char const *s)
|
void ft_putstr(char const *s)
|
||||||
{
|
{
|
||||||
write(1, s, ft_strlen(s));
|
if (s != NULL)
|
||||||
|
write(1, s, ft_strlen(s));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 23:06:30 by tmaze #+# #+# */
|
/* Created: 2018/04/07 23:06:30 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 23:08:07 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:26:43 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,5 +14,6 @@
|
|||||||
|
|
||||||
void ft_putstr_fd(char const *s, int fd)
|
void ft_putstr_fd(char const *s, int fd)
|
||||||
{
|
{
|
||||||
write(fd, s, ft_strlen(s));
|
if (s != NULL && fd >= 0)
|
||||||
|
write(fd, s, ft_strlen(s));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/06 23:27:33 by tmaze #+# #+# */
|
/* Created: 2018/04/06 23:27:33 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 11:16:10 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:04:24 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ void ft_strclr(char *s)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (s[i])
|
if (s != NULL)
|
||||||
s[i++] = '\0';
|
while (s[i])
|
||||||
|
s[i++] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 15:10:56 by tmaze #+# #+# */
|
/* Created: 2018/04/07 15:10:56 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 15:12:29 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:09:20 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,5 +14,5 @@
|
|||||||
|
|
||||||
int ft_strequ(char const *s1, char const *s2)
|
int ft_strequ(char const *s1, char const *s2)
|
||||||
{
|
{
|
||||||
return (ft_strcmp(s1, s2) == 0);
|
return ((s1 != NULL && s2 != NULL) ? ft_strcmp(s1, s2) == 0 : 0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 11:17:26 by tmaze #+# #+# */
|
/* Created: 2018/04/07 11:17:26 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 11:41:57 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:05:25 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ void ft_striter(char *s, void (*f)(char*))
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (s[i])
|
if (s != NULL && f != NULL)
|
||||||
(*f)(&s[i++]);
|
while (s[i])
|
||||||
|
(*f)(&s[i++]);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 11:36:12 by tmaze #+# #+# */
|
/* Created: 2018/04/07 11:36:12 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 11:48:32 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:06:17 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
while (s[++i])
|
if (s != NULL && f != NULL)
|
||||||
(*f)(i, &s[i]);
|
while (s[++i])
|
||||||
|
(*f)(i, &s[i]);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 16:30:47 by tmaze #+# #+# */
|
/* Created: 2018/04/07 16:30:47 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 16:56:01 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:11:36 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,7 +16,9 @@ char *ft_strjoin(char const *s1, char const *s2)
|
|||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if ((ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) != NULL)
|
ret = NULL;
|
||||||
|
if (s1 != NULL && s2 != NULL &&\
|
||||||
|
(ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) != NULL)
|
||||||
{
|
{
|
||||||
ft_strcpy(ret, s1);
|
ft_strcpy(ret, s1);
|
||||||
ft_strcat(ret, s2);
|
ft_strcat(ret, s2);
|
||||||
|
13
ft_strlcpy.c
13
ft_strlcpy.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/09 11:55:11 by tmaze #+# #+# */
|
/* Created: 2018/04/09 11:55:11 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/09 13:27:12 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:36:45 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,8 +16,11 @@ size_t ft_strlcpy(char *restrict dst, const char *restrict src, size_t size)
|
|||||||
{
|
{
|
||||||
size_t src_len;
|
size_t src_len;
|
||||||
|
|
||||||
src_len = (size_t)ft_strlen(src);
|
if (dst != NULL && src != NULL)
|
||||||
dst = ft_strncpy(dst, src, (src_len > size) ? size : src_len);
|
{
|
||||||
dst[(src_len > size) ? size - 1 : src_len] = '\0';
|
src_len = (size_t)ft_strlen(src);
|
||||||
return (ft_strlen(src));
|
dst = ft_strncpy(dst, src, (src_len > size) ? size : src_len);
|
||||||
|
dst[(src_len > size) ? size - 1 : src_len] = '\0';
|
||||||
|
}
|
||||||
|
return ((src != NULL) ? ft_strlen(src) : 0);
|
||||||
}
|
}
|
||||||
|
15
ft_strmap.c
15
ft_strmap.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 14:57:22 by tmaze #+# #+# */
|
/* Created: 2018/04/07 14:57:22 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 15:00:12 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:18:41 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,9 +19,14 @@ char *ft_strmap(char const *s, char (*f)(char))
|
|||||||
size_t s_len;
|
size_t s_len;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
s_len = ft_strlen(s);
|
s_len = 0;
|
||||||
ret = ft_strnew(s_len);
|
ret = NULL;
|
||||||
while (++i < s_len)
|
if (s != NULL && f != NULL)
|
||||||
ret[i] = (*f)(s[i]);
|
{
|
||||||
|
s_len = ft_strlen(s);
|
||||||
|
if ((ret = ft_strnew(s_len)) != NULL)
|
||||||
|
while (++i < s_len)
|
||||||
|
ret[i] = (*f)(s[i]);
|
||||||
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
15
ft_strmapi.c
15
ft_strmapi.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 15:00:23 by tmaze #+# #+# */
|
/* Created: 2018/04/07 15:00:23 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 15:00:24 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:19:19 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,9 +19,14 @@ char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|||||||
size_t s_len;
|
size_t s_len;
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
s_len = ft_strlen(s);
|
s_len = 0;
|
||||||
ret = ft_strnew(s_len);
|
ret = NULL;
|
||||||
while (++i < s_len)
|
if (s != NULL && f != NULL)
|
||||||
ret[i] = (*f)(i, s[i]);
|
{
|
||||||
|
s_len = ft_strlen(s);
|
||||||
|
if ((ret = ft_strnew(s_len)) != NULL)
|
||||||
|
while (++i < s_len)
|
||||||
|
ret[i] = (*f)(i, s[i]);
|
||||||
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 15:24:01 by tmaze #+# #+# */
|
/* Created: 2018/04/07 15:24:01 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 15:33:17 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:09:47 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,5 +14,5 @@
|
|||||||
|
|
||||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||||
{
|
{
|
||||||
return (ft_strncmp(s1, s2, n) == 0);
|
return ((s1 != NULL && s2 != NULL) ? ft_strncmp(s1, s2, n) == 0 : 0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 17:54:29 by tmaze #+# #+# */
|
/* Created: 2018/04/07 17:54:29 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/08 16:54:13 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:12:54 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -66,9 +66,16 @@ char **ft_strsplit(char const *s, char c)
|
|||||||
int nb_words;
|
int nb_words;
|
||||||
char **tab;
|
char **tab;
|
||||||
|
|
||||||
nb_words = count_words(s, c);
|
nb_words = 0;
|
||||||
if ((tab = (char**)malloc(sizeof(char**) * (nb_words + 1))) == NULL)
|
tab = NULL;
|
||||||
|
if (s != NULL)
|
||||||
|
{
|
||||||
|
nb_words = count_words(s, c);
|
||||||
|
if ((tab = (char**)malloc(sizeof(char**) * (nb_words + 1))) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
tab[nb_words] = NULL;
|
||||||
|
return (get_table(s, c, tab));
|
||||||
|
}
|
||||||
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
tab[nb_words] = NULL;
|
|
||||||
return (get_table(s, c, tab));
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 15:35:49 by tmaze #+# #+# */
|
/* Created: 2018/04/07 15:35:49 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/07 16:02:41 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:16:44 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,9 +14,10 @@
|
|||||||
|
|
||||||
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if ((ret = ft_strnew(len)) != NULL)
|
ret = NULL;
|
||||||
|
if (s != NULL && (ret = ft_strnew(len)) != NULL)
|
||||||
ret = ft_strncpy(ret, &s[start], len);
|
ret = ft_strncpy(ret, &s[start], len);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
31
ft_strtrim.c
31
ft_strtrim.c
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2018/04/07 17:00:34 by tmaze #+# #+# */
|
/* Created: 2018/04/07 17:00:34 by tmaze #+# #+# */
|
||||||
/* Updated: 2018/04/08 16:33:22 by tmaze ### ########.fr */
|
/* Updated: 2018/04/10 14:15:23 by tmaze ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,22 +20,23 @@ char *ft_strtrim(char const *s)
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
start = 0;
|
if (s != NULL)
|
||||||
len = 0;
|
|
||||||
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
|
|
||||||
i++;
|
|
||||||
start = i;
|
|
||||||
in_word = 1;
|
|
||||||
while (i == 0 || s[i - 1])
|
|
||||||
{
|
{
|
||||||
if (in_word && (!ft_isprint(s[i]) || s[i] == ' '))
|
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
|
||||||
|
i++;
|
||||||
|
start = i;
|
||||||
|
in_word = 1;
|
||||||
|
while (i == 0 || s[i - 1])
|
||||||
{
|
{
|
||||||
len = i - start;
|
if (in_word && (!ft_isprint(s[i]) || s[i] == ' '))
|
||||||
in_word = 0;
|
{
|
||||||
|
len = i - start;
|
||||||
|
in_word = 0;
|
||||||
|
}
|
||||||
|
else if (!in_word && ft_isprint(s[i]) && s[i] != ' ')
|
||||||
|
in_word = 1;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
else if (!in_word && ft_isprint(s[i]) && s[i] != ' ')
|
|
||||||
in_word = 1;
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return (ft_strsub(s, start, len));
|
return ((s != NULL) ? ft_strsub(s, start, len) : NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user