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); }