42_minishell/utils/ft_is_in_quote.c
2023-03-28 15:55:08 +02:00

42 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
/* Updated: 2023/03/27 15:32:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
#include <sys/types.h>
int ft_is_in_quote(const char *str, size_t n)
{
ssize_t i;
i = -1;
while (str[++i] != '\0' && i < (ssize_t) n)
{
if (str[i] == '\'')
{
i++;
while (str[i] != '\'' && str[i] != '\0')
{
if (i == (ssize_t) n)
return (1);
i++;
}
}
if (str[i] == '"')
{
while (str[++i] != '"' && str[i] != '\0')
if (i == (ssize_t) n)
return (2);
}
}
return (0);
}