diff --git a/format/format.c b/format/format.c index 915ddcb..31c006e 100644 --- a/format/format.c +++ b/format/format.c @@ -24,8 +24,10 @@ static char *ft_spacer_after(const char *str) i = 1; while (out[i] != '\0') { - while (ft_is_in_quote(out, i)) + while (ft_is_in_quote(out, i - 1)) i++; + if (out[i] == '\0') + break ; if (ft_is_in("><|", out[i - 1])) { while (out[i] == out[i - 1]) @@ -56,6 +58,8 @@ static char *ft_spacer_before(const char *str) { while (ft_is_in_quote(out, i)) i++; + if (out[i] == '\0') + break ; if (ft_is_in("><|", out[i + 1])) { while (out[i] == ' ') @@ -83,6 +87,8 @@ static void ft_space_simplifier(char *str) { if (ft_is_in_quote(str, i)) i++; + if (str[i] != '\0') + break ; y = 0; while (str[y + i] == ' ') y++; diff --git a/syntax/syntax.c b/syntax/syntax.c index 07afe9f..4366c21 100644 --- a/syntax/syntax.c +++ b/syntax/syntax.c @@ -84,7 +84,7 @@ static int ft_special_char_dub(const char *str) } i = i + y; } - else + else if (str[i] != '\0') i++; } return (0); diff --git a/utils/ft_is_in_quote.c b/utils/ft_is_in_quote.c index c433136..c2d756e 100644 --- a/utils/ft_is_in_quote.c +++ b/utils/ft_is_in_quote.c @@ -14,26 +14,32 @@ int ft_is_in_quote(const char *str, size_t n) { - size_t double_quoted; - size_t simple_quoted; size_t i; - double_quoted = 0; - simple_quoted = 0; i = 0; while (str[i] != '\0' && i < n) { + if (str[i] == '\'') + { + i++; + while (str[i] != '\'' && str[i] != '\0') + { + if (i == n) + return (1); + i++; + } + } if (str[i] == '"') { - if (simple_quoted == 0) - double_quoted = !double_quoted; - } - else if (str[i] == '\'') - { - if (double_quoted == 0) - simple_quoted = !simple_quoted; + i++; + while (str[i] != '"' && str[i] != '\0') + { + if (i == n) + return (2); + i++; + } } i++; } - return (simple_quoted + double_quoted * 2); + return (0); }