42_minishell/utils/ft_is_in_quote.c

41 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 15:39:25 by cchauvet #+# #+# */
/* Updated: 2023/03/30 15:52:10 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
int ft_is_in_quote(const char *str, size_t n)
{
size_t i;
ssize_t start;
start = -1;
i = 0;
while (str[i] != '\0')
{
if (i == n)
break ;
if (str[i] == '\"' || str[i] == '\'')
{
if (start == -1)
start = i;
else if (str[i] == str[start])
start = -1;
}
i++;
}
if (start == -1)
return (0);
if (str[start] == '\'')
return (1);
return (2);
}