42_minishell/utils/ft_quote_remover.c
2023-03-29 19:07:57 +02:00

51 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_quote_remover.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
/* Updated: 2023/03/29 15:11:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
static void ft_remove_quote_and_reset(char *str, ssize_t *start, ssize_t *stop)
{
ft_strshift(str + *start, -1);
ft_strshift(str + *stop - 1, -1);
*start = -1;
*stop = -1;
}
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_remove_quote_and_reset(str, &start, &stop);
i = i - 1;
}
else
i++;
}
return (str);
}