42_minishell/utils/ft_is_in_quote.c

40 lines
1.3 KiB
C
Raw Normal View History

2023-02-21 08:35:08 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
2023-02-21 17:12:16 -05:00
/* Updated: 2023/02/21 23:08:10 by cchauvet ### ########.fr */
2023-02-21 08:35:08 -05:00
/* */
/* ************************************************************************** */
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;
}
2023-02-21 17:12:16 -05:00
else if (str[i] == '\'')
2023-02-01 11:28:38 -05:00
{
if (double_quoted == 0)
simple_quoted = !simple_quoted;
}
i++;
}
2023-02-21 17:12:16 -05:00
return (simple_quoted + double_quoted * 2);
2023-02-01 11:28:38 -05:00
}