42_minishell/utils/ft_is_in_quote.c

41 lines
1.3 KiB
C
Raw Normal View History

2023-02-21 08:35:08 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_in_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
2023-03-30 09:43:57 -04:00
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
2023-02-21 08:35:08 -05:00
/* +#+#+#+#+#+ +#+ */
2023-03-30 09:43:57 -04:00
/* Created: 2023/03/30 15:39:25 by cchauvet #+# #+# */
/* Updated: 2023/03/30 15:40:06 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
{
2023-03-30 09:43:57 -04:00
size_t i;
ssize_t start;
2023-02-01 11:28:38 -05:00
2023-03-30 09:43:57 -04:00
start = -1;
i = 0;
while (str[i] != '\0')
2023-02-01 11:28:38 -05:00
{
2023-03-30 09:43:57 -04:00
if (i == n)
break ;
if (str[i] == '\"' || str[i] == '\'')
2023-02-01 11:28:38 -05:00
{
2023-03-30 09:43:57 -04:00
if (start == -1)
start = i;
else if (str[i] == str[start])
start = -1;
2023-02-01 11:28:38 -05:00
}
2023-03-30 09:43:57 -04:00
i++;
2023-02-01 11:28:38 -05:00
}
2023-03-30 09:43:57 -04:00
if (start == -1)
return ((str[i] == '\'') + (str[i] == '\"') * 2);
if (str[start] == '\'')
return (1);
return (2);
2023-02-01 11:28:38 -05:00
}