42_minishell/utils/ft_is_in_quote.c

30 lines
472 B
C
Raw Normal View History

2023-02-01 11:28:38 -05:00
#include "utils.h"
int ft_is_in_quote(const char *str, size_t n)
2023-02-01 11:28:38 -05:00
{
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);
}