summaryrefslogtreecommitdiffstats
path: root/libft/ft_split.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p6.le-101.fr>2019-10-30 15:00:17 +0100
committerRudy Bousset <rbousset@z2r5p6.le-101.fr>2019-10-30 15:00:17 +0100
commita3f3fc742daa4b28094b5ebe9be60263c41979d1 (patch)
tree5a6ce0fba04b55d6f4607038eeace0396e97f0e6 /libft/ft_split.c
parentcommit, lotta stuff (diff)
download42-minishell-a3f3fc742daa4b28094b5ebe9be60263c41979d1.tar.gz
42-minishell-a3f3fc742daa4b28094b5ebe9be60263c41979d1.tar.bz2
42-minishell-a3f3fc742daa4b28094b5ebe9be60263c41979d1.tar.xz
42-minishell-a3f3fc742daa4b28094b5ebe9be60263c41979d1.tar.zst
42-minishell-a3f3fc742daa4b28094b5ebe9be60263c41979d1.zip
New libft, feelsgoodman
Diffstat (limited to 'libft/ft_split.c')
-rw-r--r--libft/ft_split.c109
1 files changed, 0 insertions, 109 deletions
diff --git a/libft/ft_split.c b/libft/ft_split.c
deleted file mode 100644
index 7c706cf..0000000
--- a/libft/ft_split.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_split.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 19:24:20 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:37:16 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include <stddef.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-static uint8_t
- ft_check(int c, char sep)
-{
- if (c == sep)
- return (1);
- return (0);
-}
-
-static size_t
- ft_strlen_plus(const char *str, char c)
-{
- size_t i;
- size_t count;
- uint8_t ibool;
-
- i = 0;
- count = 0;
- ibool = 1;
- while (str[i])
- {
- while (ft_check(str[i], c) && str[i])
- i++;
- while (!ft_check(str[i], c) && str[i])
- {
- if (ibool == 1)
- count++;
- ibool = 0;
- i++;
- }
- ibool = 1;
- }
- return (count);
-}
-
-static size_t
- ft_strlen_again(const char *str, char c)
-{
- size_t i;
-
- i = 0;
- while (!ft_check(str[i], c) && str[i])
- i++;
- return (i);
-}
-
-static char
- *ft_strdup_plus(const char *src, char c)
-{
- size_t i;
- size_t slen;
- char *nstr;
-
- i = 0;
- slen = ft_strlen_again(src, c) + 1;
- if (!(nstr = (char*)ft_calloc(slen, sizeof(char))))
- return (NULL);
- while (!ft_check(src[i], c) && src[i])
- {
- nstr[i] = src[i];
- i++;
- }
- nstr[i] = '\0';
- return (nstr);
-}
-
-char
- **ft_split(const char *s, char c)
-{
- size_t i;
- size_t j;
- char **best_split;
-
- i = 0;
- j = 0;
- if (!(best_split = (char **)ft_calloc(ft_strlen_plus(s, c) + 1,
- sizeof(char *))))
- return (NULL);
- while (s[i])
- {
- while (ft_check(s[i], c) && s[i])
- i++;
- while (!ft_check(s[i], c) && s[i])
- {
- best_split[j] = ft_strdup_plus(&s[i], c);
- i += ft_strlen_again(&s[i], c);
- j++;
- }
- }
- best_split[j] = 0;
- return (best_split);
-}