fix: quote verif is better

This commit is contained in:
Camille Chauvet 2023-03-13 19:28:46 +01:00
parent 08261b1921
commit ee3d535393
3 changed files with 26 additions and 14 deletions

View File

@ -24,8 +24,10 @@ static char *ft_spacer_after(const char *str)
i = 1; i = 1;
while (out[i] != '\0') while (out[i] != '\0')
{ {
while (ft_is_in_quote(out, i)) while (ft_is_in_quote(out, i - 1))
i++; i++;
if (out[i] == '\0')
break ;
if (ft_is_in("><|", out[i - 1])) if (ft_is_in("><|", out[i - 1]))
{ {
while (out[i] == 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)) while (ft_is_in_quote(out, i))
i++; i++;
if (out[i] == '\0')
break ;
if (ft_is_in("><|", out[i + 1])) if (ft_is_in("><|", out[i + 1]))
{ {
while (out[i] == ' ') while (out[i] == ' ')
@ -83,6 +87,8 @@ static void ft_space_simplifier(char *str)
{ {
if (ft_is_in_quote(str, i)) if (ft_is_in_quote(str, i))
i++; i++;
if (str[i] != '\0')
break ;
y = 0; y = 0;
while (str[y + i] == ' ') while (str[y + i] == ' ')
y++; y++;

View File

@ -84,7 +84,7 @@ static int ft_special_char_dub(const char *str)
} }
i = i + y; i = i + y;
} }
else else if (str[i] != '\0')
i++; i++;
} }
return (0); return (0);

View File

@ -14,26 +14,32 @@
int ft_is_in_quote(const char *str, size_t n) int ft_is_in_quote(const char *str, size_t n)
{ {
size_t double_quoted;
size_t simple_quoted;
size_t i; size_t i;
double_quoted = 0;
simple_quoted = 0;
i = 0; i = 0;
while (str[i] != '\0' && i < n) 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 (str[i] == '"')
{ {
if (simple_quoted == 0) i++;
double_quoted = !double_quoted; while (str[i] != '"' && str[i] != '\0')
}
else if (str[i] == '\'')
{ {
if (double_quoted == 0) if (i == n)
simple_quoted = !simple_quoted; return (2);
i++;
}
} }
i++; i++;
} }
return (simple_quoted + double_quoted * 2); return (0);
} }