From 94e55d1d8b118e02bda24ecf0f4b8e7f1934097c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 28 Feb 2025 14:13:50 +0100 Subject: [PATCH] quote removal: handle nested quotes --- src/parser/remove_quotes/remove_quotes.c | 4 ++-- tests/quote_removal.c | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/parser/remove_quotes/remove_quotes.c b/src/parser/remove_quotes/remove_quotes.c index 31c0da7..d2e3c34 100644 --- a/src/parser/remove_quotes/remove_quotes.c +++ b/src/parser/remove_quotes/remove_quotes.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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++; } diff --git a/tests/quote_removal.c b/tests/quote_removal.c index 6568b5e..99164e8 100644 --- a/tests/quote_removal.c +++ b/tests/quote_removal.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); }