69 lines
1.7 KiB
C
69 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strsplitstr2.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2018/11/26 11:33:06 by tmaze #+# #+# */
|
|
/* Updated: 2018/11/26 12:42:46 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
static int isin(char c, char *str)
|
|
{
|
|
size_t i;
|
|
|
|
i = 0;
|
|
while (str[i])
|
|
if (c == str[i++])
|
|
return (1);
|
|
return (0);
|
|
}
|
|
|
|
static void ft_cntdelstr(void* content, size_t content_size)
|
|
{
|
|
ft_strdel((char**)content);
|
|
content_size = 0;
|
|
}
|
|
|
|
t_list *ft_strsplitstr2(char *str, char *split)
|
|
{
|
|
size_t i;
|
|
size_t j;
|
|
char *token;
|
|
t_list *lst;
|
|
t_list *new;
|
|
|
|
lst = NULL;
|
|
i = 0;
|
|
j = 0;
|
|
while (str[i])
|
|
{
|
|
if (isin(str[i], split))
|
|
{
|
|
if ((token = ft_strnew(i - j + 1)) == NULL)
|
|
{
|
|
ft_lstdel(&lst, &ft_cntdelstr);
|
|
return (NULL);
|
|
}
|
|
token[i + j + 1] = '\0';
|
|
ft_strsub(str, j, i);
|
|
if ((new = ft_lstnew((void*)token, ft_strlen(token))) == NULL)
|
|
{
|
|
ft_strdel(&token);
|
|
ft_lstdel(&lst, &ft_cntdelstr);
|
|
return (NULL);
|
|
}
|
|
ft_lstaddend(&lst, new);
|
|
while ((isin(str[i], split)))
|
|
i++;
|
|
j = i;
|
|
}
|
|
i++;
|
|
}
|
|
return (lst);
|
|
}
|