From 57bd2453ee619c1dbe19f53a4df898e7095815be Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Wed, 12 Oct 2022 19:00:31 +0200 Subject: [PATCH] test --- ft_split.old | 87 ---------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 ft_split.old diff --git a/ft_split.old b/ft_split.old deleted file mode 100644 index e3ea337..0000000 --- a/ft_split.old +++ /dev/null @@ -1,87 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: nkimel - -static void *free_array(char **a) -{ - size_t i; - - if (a != NULL) - { - i = 0; - while (a[i] != NULL) - free(a[i++]); - free(a); - } - return (NULL); -} - -static size_t skip_char(const char **s, char c, bool invert) -{ - size_t i; - const char *p; - - i = 0; - p = *s; - while (((!invert && *p == c) || (invert && *p != c)) && *p != '\0') - { - p++; - i++; - } - *s = p; - return (i); -} - -static size_t count_elems(const char *s, char c) -{ - size_t n_elem; - - n_elem = 0; - skip_char(&s, c, false); - while (*s != '\0') - { - skip_char(&s, c, true); - skip_char(&s, c, false); - n_elem++; - } - return (n_elem); -} - -char **ft_split(char const *s, char c) -{ - char **array; - size_t n_elem; - size_t arr_i; - const char *rem_s; - size_t len; - - if (s == NULL) - return (NULL); - n_elem = count_elems(s, c); - array = ft_calloc(n_elem + 1, sizeof(char *)); - if (array == NULL) - return (array); - skip_char(&s, c, false); - arr_i = 0; - while (arr_i < n_elem) - { - rem_s = s; - len = skip_char(&s, c, true); - array[arr_i] = ft_substr(rem_s, 0, len); - if (array[arr_i++] == NULL) - return (free_array(array)); - skip_char(&s, c, false); - } - return (array); -}