quote removal: if given null, return null

This commit is contained in:
Khaïs COLIN 2025-03-07 11:08:35 +01:00
parent 0fecded23b
commit 7b76c1a71f
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 14 additions and 2 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:09:17 by khais ### ########.fr */
/* Updated: 2025/03/07 11:09:30 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,11 +18,15 @@
** unquoted quotes.
**
** The new worddesc will have the marker set to NULL.
**
** If word is null return null.
*/
t_worddesc *remove_quotes(t_worddesc *word)
{
t_worddesc *output;
if (word == NULL)
return (NULL);
output = worddesc_create(ft_strdup(word->word), word->flags, NULL);
if (output->word == NULL)
return (worddesc_destroy(output), NULL);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/28 13:46:56 by khais #+# #+# */
/* Updated: 2025/03/07 10:59:54 by khais ### ########.fr */
/* Updated: 2025/03/07 11:07:59 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,7 +35,15 @@ static void test_quote_removal_no_quotes_single_word(void)
worddesc_destroy(got_word);
}
static void test_quote_removal_null(void)
{
t_worddesc *word = NULL;
t_worddesc *got_word = remove_quotes(word);
assert(got_word == NULL);
}
int main(void) {
test_quote_removal_no_quotes_single_word();
test_quote_removal_null();
return (0);
}