diff --git a/utils/ft_split_charset_quoted.c b/utils/ft_split_charset_quoted.c index 268007c..8dfede3 100644 --- a/utils/ft_split_charset_quoted.c +++ b/utils/ft_split_charset_quoted.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */ -/* Updated: 2023/04/14 14:14:25 by erey-bet ### ########.fr */ +/* Updated: 2023/04/14 15:53:49 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,30 +30,38 @@ int get_strs(const char *to_split, const char *charset, char ***strs, int *i) int j; int x; int y; + int check; x = -1; j = 0; while (to_split[++x]) { y = -1; + check = 1; while (charset[++y]) { if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x)) { - y = 0; - if (to_split[x + 1]) - { - x++; - if (new_strs(strs, to_split, i, &j)) - return (1); - } + check = 0; + if (new_strs(strs, to_split, i, &j)) + return (1); } } - (*strs)[(*i)][j++] = to_split[x]; + if (check) + (*strs)[(*i)][j++] = to_split[x]; } return (0); } +void free_set_null(char ***strs, int i) +{ + if (ft_strlen((*strs)[i]) == 0) + { + free((*strs)[i]); + (*strs)[i] = NULL; + } +} + char **ft_split_charset_quoted(const char *to_split, const char *charset) { char **strs; @@ -77,18 +85,6 @@ char **ft_split_charset_quoted(const char *to_split, const char *charset) free(strs); return (NULL); } + free_set_null(&strs, i); return (strs); } - -/*#include - -int main(int argc, char **argv) -{ - char **strs; - if (argc == 3) - strs = ft_split_charset_quoted(argv[1], argv[2]); - int i = -1; - while (strs[++i]) - printf("%s\n", strs[i]); - return (0); -}*/