42_minishell/utils/ft_is_in_quote.c
Camille Chauvet 33cccda0ad start
2023-02-01 17:28:38 +01:00

30 lines
466 B
C

#include "utils.h"
int ft_is_in_quote(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] == '"')
{
if (simple_quoted == 0)
double_quoted = !double_quoted;
}
if (str[i] == '\'')
{
if (double_quoted == 0)
simple_quoted = !simple_quoted;
}
i++;
}
return (simple_quoted == 1 + (double_quoted == 1) * 2);
}