quote removal: handle nested quotes

This commit is contained in:
Khaïs COLIN 2025-02-28 14:13:50 +01:00
parent a3d2143b8b
commit 94e55d1d8b
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 25 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/28 13:52:02 by khais #+# #+# */
/* Updated: 2025/03/07 11:13:49 by khais ### ########.fr */
/* Updated: 2025/03/07 11:20:48 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,7 +37,7 @@ t_worddesc *remove_quotes(t_worddesc *word)
i = 0;
while (word->word[i] != '\0')
{
if (!is_quote(word->word[i]))
if (!is_quote(word->word[i]) || is_quote(word->marker[i]))
buf = ft_buffer_pushchar(buf, word->word[i]);
i++;
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/28 13:46:56 by khais #+# #+# */
/* Updated: 2025/03/07 11:14:48 by khais ### ########.fr */
/* Updated: 2025/03/07 11:19:37 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,10 +62,32 @@ static void test_quote_removal_double_quotes(void)
worddesc_destroy(got_word);
}
static void test_quote_removal_mixed_single_in_double(void)
{
t_worddesc *word = create_single_word("\"'word'\"");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("'word'", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
static void test_quote_removal_mixed_double_in_single(void)
{
t_worddesc *word = create_single_word("'\"word\"'");
t_worddesc *got_word = remove_quotes(word);
assert_strequal("\"word\"", got_word->word);
assert(got_word->marker == NULL);
worddesc_destroy(word);
worddesc_destroy(got_word);
}
int main(void) {
test_quote_removal_no_quotes_single_word();
test_quote_removal_null();
test_quote_removal_single_quotes();
test_quote_removal_double_quotes();
test_quote_removal_mixed_single_in_double();
test_quote_removal_mixed_double_in_single();
return (0);
}