fix: quote closed verif

This commit is contained in:
Camille Chauvet 2023-03-30 15:43:57 +02:00
parent 3374d21cad
commit 41bbe2bc0b
2 changed files with 23 additions and 24 deletions

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */ /* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
/* Updated: 2023/03/30 12:45:18 by cchauvet ### ########.fr */ /* Updated: 2023/03/30 15:42:13 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -86,7 +86,7 @@ static int ft_empty_verif(const char *str)
size_t i; size_t i;
i = 0; i = 0;
while (str[i] == ' ') while (str[i] == ' ' || str[i] == '\"' || str[i] == '\'')
i++; i++;
return (str[i] == '\0'); return (str[i] == '\0');
} }

View File

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