From 41bbe2bc0b7da19f8ae49be9600dd189dbc97455 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Thu, 30 Mar 2023 15:43:57 +0200 Subject: [PATCH] fix: quote closed verif --- syntax/syntax.c | 4 ++-- utils/ft_is_in_quote.c | 43 +++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/syntax/syntax.c b/syntax/syntax.c index c158681..0de5fc6 100644 --- a/syntax/syntax.c +++ b/syntax/syntax.c @@ -6,7 +6,7 @@ /* By: cchauvet int ft_is_in_quote(const char *str, size_t n) { - ssize_t i; + size_t i; + ssize_t start; - i = -1; - while (str[++i] != '\0' && i < (ssize_t) n) + start = -1; + i = 0; + while (str[i] != '\0') { - if (str[i] == '\'') + if (i == n) + break ; + if (str[i] == '\"' || str[i] == '\'') { - i++; - while (str[i] != '\'' && str[i] != '\0') - { - if (i == (ssize_t) n) - return (1); - i++; - } - } - if (str[i] == '"') - { - while (str[++i] != '"' && str[i] != '\0') - if (i == (ssize_t) n) - return (2); + if (start == -1) + start = i; + else if (str[i] == str[start]) + start = -1; } + i++; } - return (0); + if (start == -1) + return ((str[i] == '\'') + (str[i] == '\"') * 2); + if (str[start] == '\'') + return (1); + return (2); }