Browse Source

updated

master
narnaud 3 years ago
parent
commit
9354b6e1ee
  1. 25
      Makefile
  2. 12
      conv/ft_atoi.c
  3. 27
      dlist/ft_add.c
  4. 20
      dlist/ft_n.c
  5. 41
      dlist/ft_to_arr.c
  6. 32
      i_slist/ft_first.c
  7. 25
      i_slist/ft_free.c
  8. 27
      i_slist/ft_is_in.c
  9. 52
      libft.h
  10. 26
      mem/ft_free_split.c
  11. 18
      nbr/ft_croissant.c
  12. 18
      nbr/ft_decroissant.c
  13. 10
      slist/ft_add_back.c
  14. 6
      slist/ft_add_front.c
  15. 10
      slist/ft_clear.c
  16. 6
      slist/ft_delone.c
  17. 8
      slist/ft_iter.c
  18. 6
      slist/ft_last.c
  19. 14
      slist/ft_map.c
  20. 10
      slist/ft_new.c
  21. 6
      slist/ft_size.c
  22. 0
      str/ft_chr.c
  23. 0
      str/ft_dup.c
  24. 0
      str/ft_iteri.c
  25. 0
      str/ft_join.c
  26. 0
      str/ft_lcat.c
  27. 0
      str/ft_lcpy.c
  28. 18
      str/ft_len.c
  29. 0
      str/ft_mapi.c
  30. 0
      str/ft_ncmp.c
  31. 0
      str/ft_nstr.c
  32. 0
      str/ft_rchr.c
  33. 0
      str/ft_rev.c
  34. 105
      str/ft_split.c
  35. 0
      str/ft_sub.c
  36. 0
      str/ft_trim.c

25
Makefile

@ -3,24 +3,29 @@ NAME = libft.a
SRCS = is/ft_isalpha.c is/ft_isdigit.c is/ft_isascii.c is/ft_isprint.c \
is/ft_isalnum.c
SRCS += str/ft_strlen.c str/ft_strlcpy.c str/ft_strlcat.c str/ft_strchr.c \
str/ft_strrchr.c str/ft_strncmp.c str/ft_strnstr.c str/ft_strdup.c \
str/ft_substr.c str/ft_strjoin.c str/ft_strtrim.c str/ft_split.c \
str/ft_strrev.c str/ft_strmapi.c str/ft_striteri.c
SRCS += str/ft_len.c str/ft_lcpy.c str/ft_lcat.c str/ft_chr.c \
str/ft_rchr.c str/ft_ncmp.c str/ft_nstr.c str/ft_dup.c \
str/ft_sub.c str/ft_join.c str/ft_trim.c str/ft_split.c \
str/ft_rev.c str/ft_mapi.c str/ft_iteri.c
SRCS += conv/ft_toupper.c conv/ft_tolower.c conv/ft_atoi.c conv/ft_itoa.c \
conv/ft_itox.c conv/ft_utoa.c
SRCS += mem/ft_bzero.c mem/ft_memset.c mem/ft_memchr.c mem/ft_memcpy.c \
mem/ft_memcmp.c mem/ft_memmove.c mem/ft_calloc.c
mem/ft_memcmp.c mem/ft_memmove.c mem/ft_calloc.c mem/ft_free_split.c
SRCS += put/ft_putchar_fd.c put/ft_putnbr_fd.c put/ft_putendl_fd.c put/ft_putstr_fd.c
SRCS += put/ft_putchar_fd.c put/ft_putnbr_fd.c put/ft_putendl_fd.c \
put/ft_putstr_fd.c
SRCS += nbr/ft_nbrlen.c
SRCS += nbr/ft_nbrlen.c nbr/ft_croissant.c nbr/ft_decroissant.c
SRCS += lst/ft_lstsize.c lst/ft_lstnew.c lst/ft_lstlast.c \
lst/ft_lstadd_back.c lst/ft_lstadd_front.c lst/ft_lstdelone.c \
lst/ft_lstclear.c lst/ft_lstiter.c lst/ft_lstmap.c
SRCS += slist/ft_size.c slist/ft_new.c slist/ft_last.c \
slist/ft_add_back.c slist/ft_add_front.c slist/ft_delone.c \
slist/ft_clear.c slist/ft_iter.c slist/ft_map.c
SRCS += i_slist/ft_free.c i_slist/ft_first.c i_slist/ft_is_in.c
SRCS += dlist/ft_add.c dlist/ft_n.c dlist/ft_to_arr.c
OBJS = $(SRCS:.c=.o)

12
conv/ft_atoi.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/18 17:06:25 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */
/* Updated: 2022/03/25 14:14:45 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,12 @@
int ft_atoi(const char *str)
{
int sign;
int nb;
double nb;
nb = 0;
sign = 1;
if (!ft_strncmp(str, "-2147483648", 11))
return (-2147483648);
while (*str == ' ' || (*str >= '\t' && *str <= '\r'))
str++;
if (*str == '-' && ++str)
@ -27,11 +29,11 @@ int ft_atoi(const char *str)
str++;
while (*str >= '0' && *str <= '9')
{
if (nb < 0 && sign > 0)
nb = nb * 10 + (*str - '0') % 10;
if (nb > 2147483647 && sign > 0)
return (-1);
else if (nb < 0 && sign < 0)
else if (nb > 2147486648 && sign < 0)
return (0);
nb = nb * 10 + (*str - '0') % 10;
str++;
}
return ((int)(sign * nb));

27
dlist/ft_add.c

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_add.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/24 10:46:25 by narnaud #+# #+# */
/* Updated: 2022/03/25 14:15:13 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_dlist *ft_dlst_add(t_dlist *prev, void *content)
{
t_dlist *new;
if (!content)
return (prev);
new = ft_calloc(1, sizeof(t_dlist));
if (prev)
prev->next = new;
new->previous = prev;
new->content = content;
return (new);
}

20
dlist/ft_n.c

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dlst_n.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/24 10:51:20 by narnaud #+# #+# */
/* Updated: 2022/03/24 11:27:40 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_dlist *ft_dlst_n(t_dlist *lst, size_t n)
{
while (n-- && lst)
lst = lst->next;
return (lst);
}

41
dlist/ft_to_arr.c

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dlst_to_arr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/24 10:50:10 by narnaud #+# #+# */
/* Updated: 2022/03/24 11:33:57 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char **ft_dlst_to_arr(t_dlist *ptr)
{
char **ret;
t_dlist *last;
t_dlist *tmp;
size_t count;
last = ptr;
count = 1;
if (!ptr)
return (ft_calloc(1, sizeof(char *)));
while (ptr->previous)
{
ptr = ptr->previous;
count++;
}
ret = ft_calloc(count + 1, sizeof(char *));
ret[count] = NULL;
while (count--)
{
ret[count] = last->content;
tmp = last;
free(last);
last = tmp->previous;
}
return (ret);
}

32
i_slist/ft_first.c

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_first.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 09:06:44 by narnaud #+# #+# */
/* Updated: 2022/03/25 13:26:04 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
size_t ft_ilst_first(t_i_slist *lst, int (*fct)(int a, int b))
{
int previous;
size_t i;
i = 1;
if (!lst)
return (0);
while (lst)
{
previous = lst->nb;
lst = lst->next;
if (lst && fct(previous, lst->nb))
return (i);
i++;
}
return (-1);
}

25
i_slist/ft_free.c

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 09:27:41 by narnaud #+# #+# */
/* Updated: 2022/03/25 14:18:37 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_ilst_free(t_i_slist *list)
{
t_i_slist *next;
while (list)
{
next = list->next;
free(list);
list = next;
}
}

27
i_slist/ft_is_in.c

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 13:22:49 by narnaud #+# #+# */
/* Updated: 2022/03/25 14:19:02 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_ilst_is_in(int value, t_i_slist lst)
{
if (lst.nb == value && lst.next)
return (1);
while (lst.next)
{
if (lst.nb == value)
return (1);
else
lst = *(lst.next);
}
return (0);
}

52
libft.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/19 14:42:45 by narnaud #+# #+# */
/* Updated: 2021/12/21 10:02:24 by narnaud ### ########.fr */
/* Updated: 2022/03/25 13:31:43 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,11 +17,24 @@
# include <stdlib.h>
# include <unistd.h>
typedef struct s_list
typedef struct s_slist
{
void *content;
struct s_list *next;
} t_list;
struct s_slist *next;
} t_slist;
typedef struct s_i_slist
{
int nb;
struct s_i_slist *next;
} t_i_slist;
typedef struct s_dlist
{
void *content;
struct s_dlist *next;
struct s_dlist *previous;
} t_dlist;
int ft_atoi(const char *str);
void ft_bzero(void *s, size_t n);
@ -35,15 +48,21 @@ void *ft_memchr(const void *b, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dst, const void *src, size_t n);
void *ft_memmove(void *dst, const void *src, size_t n);
void ft_free_split(char **split);
size_t ft_ilen(int nbr);
size_t ft_ulen(unsigned int nbr);
size_t ft_longbaselen(long nbr, size_t base);
int ft_croissant(int a, int b);
int ft_decroissant(int a, int b);
void *ft_memset(void *b, int c, size_t len);
char *ft_strchr(const char *s, int c);
char *ft_strdup(const char *src);
size_t ft_strlcat(char *dst, const char *src, size_t dstsize);
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize);
size_t ft_strlen(const char *s);
size_t ft_strlen_to(const char *str, char ch);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
char *ft_strrchr(const char *s, int c);
@ -64,14 +83,21 @@ void ft_putstr_fd(char *s, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **alst, t_list *new);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **alst, t_list *new);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
t_slist *ft_slst_new(void *content);
void ft_slst_add_front(t_slist **alst, t_slist *new);
int ft_slst_size(t_slist *lst);
t_slist *ft_slst_last(t_slist *lst);
void ft_slst_add_back(t_slist **alst, t_slist *new);
void ft_slst_delone(t_slist *lst, void (*del)(void *));
void ft_slst_clear(t_slist **lst, void (*del)(void *));
void ft_slst_iter(t_slist *lst, void (*f)(void *));
t_slist *ft_slst_map(t_slist *lst, void *(*f)(void *), void (*del)(void *));
size_t ft_ilst_first(t_i_slist *lst, int (*fct)(int a, int b));
void ft_ilst_free(t_i_slist *list);
int ft_ilst_is_in(int value, t_i_slist lst);
t_dlist *ft_dlst_add(t_dlist *prev, void *content);
t_dlist *ft_dlst_n(t_dlist *lst, size_t n);
char **ft_dlst_to_arr(t_dlist *ptr);
#endif

26
mem/ft_free_split.c

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 08:55:20 by narnaud #+# #+# */
/* Updated: 2022/03/25 08:57:26 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_free_split(char **split)
{
int i;
i = 0;
while (split[i])
{
free(split[i]);
i++;
}
free(split);
}

18
nbr/ft_croissant.c

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_croissant.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 09:14:45 by narnaud #+# #+# */
/* Updated: 2022/03/25 09:15:32 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_croissant(int a, int b)
{
return (a <= b);
}

18
nbr/ft_decroissant.c

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_decroissant.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/25 09:14:45 by narnaud #+# #+# */
/* Updated: 2022/03/25 10:53:14 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_decroissant(int a, int b)
{
return (a > b);
}

10
lst/ft_lstadd_back.c → slist/ft_add_back.c

@ -1,26 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back_bonus.c :+: :+: :+: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:51:11 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstadd_back(t_list **alst, t_list *new)
void ft_slst_add_back(t_slist **alst, t_slist *new)
{
t_list *i_cell;
t_slist *i_cell;
if (!alst || !new)
return ;
if (*alst)
{
i_cell = ft_lstlast(*alst);
i_cell = ft_slst_last(*alst);
i_cell->next = new;
}
else

6
lst/ft_lstadd_front.c → slist/ft_add_front.c

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front_bonus.c :+: :+: :+: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:48:11 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstadd_front(t_list **alst, t_list *new)
void ft_slst_add_front(t_slist **alst, t_slist *new)
{
if (!alst || !new)
return ;

10
lst/ft_lstclear.c → slist/ft_clear.c

@ -1,27 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:53:04 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
void ft_slst_clear(t_slist **lst, void (*del)(void *))
{
t_list *next_cell;
t_slist *next_cell;
if (!del)
return ;
while (lst && *lst)
{
next_cell = (*lst)->next;
ft_lstdelone(*lst, del);
ft_slst_delone(*lst, del);
*lst = next_cell;
}
}

6
lst/ft_lstdelone.c → slist/ft_delone.c

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone_bonus.c :+: :+: :+: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:51:53 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
void ft_slst_delone(t_slist *lst, void (*del)(void *))
{
if (!lst || !del)
return ;

8
lst/ft_lstiter.c → slist/ft_iter.c

@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter_bonus.c :+: :+: :+: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:54:03 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
void ft_slst_iter(t_slist *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
(*f)(lst->content);
if (lst->next)
ft_lstiter(lst->next, f);
ft_slst_iter(lst->next, f);
}

6
lst/ft_lstlast.c → slist/ft_last.c

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast_bonus.c :+: :+: :+: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:50:21 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstlast(t_list *lst)
t_slist *ft_slst_last(t_slist *lst)
{
if (!lst)
return (NULL);

14
lst/ft_lstmap.c → slist/ft_map.c

@ -1,29 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:54:31 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
t_slist *ft_slst_map(t_slist *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_lst;
t_slist *new_lst;
if (!lst || !f)
return (NULL);
new_lst = ft_lstnew((*f)(lst->content));
new_lst = ft_slst_new((*f)(lst->content));
if (!new_lst)
{
ft_lstclear(&new_lst, del);
ft_slst_clear(&new_lst, del);
return (NULL);
}
new_lst->next = ft_lstmap(lst->next, f, del);
new_lst->next = ft_slst_map(lst->next, f, del);
return (new_lst);
}

10
lst/ft_lstnew.c → slist/ft_new.c

@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew_bonus.c :+: :+: :+: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/20 17:36:09 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
t_list *ft_lstnew(void *content)
t_slist *ft_slst_new(void *content)
{
t_list *i_cell;
t_slist *i_cell;
i_cell = (t_list *)malloc(sizeof(*i_cell));
i_cell = (t_slist *)malloc(sizeof(*i_cell));
if (!i_cell)
return (NULL);
i_cell->content = content;

6
lst/ft_lstsize.c → slist/ft_size.c

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize_bonus.c :+: :+: :+: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:49:32 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_lstsize(t_list *lst)
int ft_slst_size(t_slist *lst)
{
size_t lst_size;

0
str/ft_strchr.c → str/ft_chr.c

0
str/ft_strdup.c → str/ft_dup.c

0
str/ft_striteri.c → str/ft_iteri.c

0
str/ft_strjoin.c → str/ft_join.c

0
str/ft_strlcat.c → str/ft_lcat.c

0
str/ft_strlcpy.c → str/ft_lcpy.c

18
str/ft_strlen.c → str/ft_len.c

@ -1,25 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* ft_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/18 16:04:47 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/25 11:57:59 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
size_t ft_strlen(const char *s)
size_t ft_strlen_to(const char *str, char ch)
{
size_t i;
i = 0;
while (s[i] != '\0')
{
while (str[i] && str[i] != ch)
i++;
return (i);
}
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}

0
str/ft_strmapi.c → str/ft_mapi.c

0
str/ft_strncmp.c → str/ft_ncmp.c

0
str/ft_strnstr.c → str/ft_nstr.c

0
str/ft_strrchr.c → str/ft_rchr.c

0
str/ft_strrev.c → str/ft_rev.c

105
str/ft_split.c

@ -6,98 +6,37 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/20 15:43:48 by narnaud #+# #+# */
/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */
/* Updated: 2022/03/25 14:56:37 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
static int ft_strlen_to(char const *str, int i, char ch, int lf_not)
{
if (!str[i])
return (i);
if ((!lf_not && str[i] == ch) || (lf_not && !(str[i] == ch)))
return (i);
return (ft_strlen_to(str, ++i, ch, lf_not));
}
static int goto_cur_word(char const *str, char ch, int *words_len, int j_word)
{
int i_word;
int i;
i_word = 0;
i = 0;
i += ft_strlen_to(str, i, ch, 1) - i;
while (i_word < j_word)
{
i += words_len[i_word++];
i += ft_strlen_to(str, i, ch, 1) - i;
}
return (i);
}
static char *ft_get_word(char const *str, char ch, int *words_len, int j_word)
char **ft_split(const char *str, char c)
{
t_dlist *words;
char *word;
int i;
int j;
char *output;
output = ft_calloc((words_len[j_word] + 1), sizeof(char));
if (output == NULL)
return (output);
i = goto_cur_word(str, ch, words_len, j_word);
j = 0;
while (j < words_len[j_word])
{
i += ft_strlen_to(str, i, ch, 1) - i;
output[j] = str[i + j];
j++;
}
output[j] = '\0';
return (output);
}
int get_words_len(int **words_len, char const *str, char ch)
{
int i;
int strlen;
int words_count;
i = 0;
words_count = 0;
strlen = ft_strlen_to(str, 0, '\0', 0);
while (i < strlen)
{
(*words_len)[words_count] = ft_strlen_to(str, i, ch, 0) - i;
i += (*words_len)[words_count] + 1;
if ((*words_len)[words_count] && ++words_count)
(*words_len)[words_count] = 0;
}
return (words_count);
}
char **ft_split(char const *str, char ch)
{
int i;
int words_count;
int *words_len;
char **output;
if (!str)
return (NULL);
i = -1;
words_len = ft_calloc(200, sizeof(int));
if (!words_len)
return (NULL);
words_count = get_words_len(&words_len, str, ch);
output = ft_calloc(words_count + 1, sizeof(char *));
if (!output)
word = NULL;
words = NULL;
if (!str)
return (NULL);
i = -1;
while (++i < words_count)
output[i] = ft_get_word(str, ch, words_len, i);
output[i] = NULL;
free(words_len);
return (output);
while (str[++i])
{
if (!word && str[i] != c)
j = 0;
if (!word && str[i] != c)
word = ft_calloc((int)ft_strlen_to(str + i, c) + 1, sizeof(char));
if (word && str[i] == c)
words = ft_dlst_add(words, word);
if (word && str[i] == c)
word = NULL;
if (str[i] != c)
word[j++] = str[i];
}
words = ft_dlst_add(words, word);
return ((char **)ft_dlst_to_arr(words));
}

0
str/ft_substr.c → str/ft_sub.c

0
str/ft_strtrim.c → str/ft_trim.c

Loading…
Cancel
Save