2023-02-15 14:52:27 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_quote_remover.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
|
2023-03-29 13:07:57 -04:00
|
|
|
/* Updated: 2023/03/29 15:11:44 by cchauvet ### ########.fr */
|
2023-02-15 14:52:27 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
2023-03-29 13:07:57 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-15 14:52:27 -05:00
|
|
|
char *ft_quote_remover(char *str)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
ssize_t start;
|
|
|
|
ssize_t stop;
|
|
|
|
|
|
|
|
start = -1;
|
2023-02-21 08:35:08 -05:00
|
|
|
stop = -1;
|
2023-02-15 14:52:27 -05:00
|
|
|
i = 0;
|
|
|
|
while (str[i] != '\0')
|
|
|
|
{
|
|
|
|
if ((str[i] == '\"' || str[i] == '\''))
|
|
|
|
{
|
|
|
|
if (start == -1)
|
|
|
|
start = i;
|
|
|
|
else if (str[i] == str[start])
|
|
|
|
stop = i;
|
|
|
|
}
|
2023-02-21 08:35:08 -05:00
|
|
|
if (stop != -1)
|
|
|
|
{
|
2023-03-29 13:07:57 -04:00
|
|
|
ft_remove_quote_and_reset(str, &start, &stop);
|
2023-03-13 10:34:43 -04:00
|
|
|
i = i - 1;
|
2023-02-21 08:35:08 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
2023-02-15 14:52:27 -05:00
|
|
|
}
|
|
|
|
return (str);
|
|
|
|
}
|