42_minishell/utils/ft_quote_remover.c
Camille Chauvet 74bbbd899a fix
2023-03-13 15:34:43 +01:00

46 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_quote_remover.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
/* Updated: 2023/02/21 14:33:28 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
char *ft_quote_remover(char *str)
{
size_t i;
ssize_t start;
ssize_t stop;
start = -1;
stop = -1;
i = 0;
while (str[i] != '\0')
{
if ((str[i] == '\"' || str[i] == '\''))
{
if (start == -1)
start = i;
else if (str[i] == str[start])
stop = i;
}
if (stop != -1)
{
ft_strshift(str + start, -1);
ft_strshift(str + stop - 1, -1);
start = -1;
stop = -1;
i = i - 1;
}
else
i++;
}
return (str);
}