From 681ca8f4896ef41cf47bf7fe82860015196c72bc Mon Sep 17 00:00:00 2001 From: Mineplay Date: Thu, 15 May 2025 10:20:54 -0500 Subject: [PATCH] feat(utf-8 string): implemented clear function --- Include/Fledasty/Strings/UTF8String.h | 1 + Src/Strings/UTF8String.c | 11 +++++++++++ Tests/Main.c | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Include/Fledasty/Strings/UTF8String.h b/Include/Fledasty/Strings/UTF8String.h index b25f8dd..eea16f1 100644 --- a/Include/Fledasty/Strings/UTF8String.h +++ b/Include/Fledasty/Strings/UTF8String.h @@ -43,6 +43,7 @@ FledastyError fledasty_utf8_string_insert_before_string(FledastyUtf8String *curr FledastyError fledasty_utf8_string_insert_after_string(FledastyUtf8String *current_string, unsigned char *after_character_string, size_t after_character_string_size, unsigned char *character_string, size_t character_string_size); FledastyError fledasty_utf8_string_pop(FledastyUtf8String *current_string); +FledastyError fledasty_utf8_string_clear(FledastyUtf8String *current_string); FledastyError fledasty_utf8_string_replace_string(FledastyUtf8String *current_string, unsigned char *replace_character_string, size_t replace_character_string_size, unsigned char *character_string, size_t character_string_size); diff --git a/Src/Strings/UTF8String.c b/Src/Strings/UTF8String.c index e50786f..d78c5b1 100644 --- a/Src/Strings/UTF8String.c +++ b/Src/Strings/UTF8String.c @@ -198,6 +198,17 @@ FledastyError fledasty_utf8_string_pop(FledastyUtf8String *current_string) { return FLEDASTY_ERROR_NONE; } +FledastyError fledasty_utf8_string_clear(FledastyUtf8String *current_string) { + if (current_string == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + current_string->size = 0; + current_string->character_string[0] = '\0'; + + return FLEDASTY_ERROR_NONE; +} + FledastyError fledasty_utf8_string_replace_string(FledastyUtf8String *current_string, unsigned char *replace_character_string, size_t replace_character_string_size, unsigned char *character_string, size_t character_string_size) { if (current_string == NULL || replace_character_string == NULL || replace_character_string_size == 0 || character_string == NULL || character_string_size == 0) { return FLEDASTY_ERROR_INVALID_POINTER; diff --git a/Tests/Main.c b/Tests/Main.c index 0906c20..61cc5e5 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -266,7 +266,8 @@ int main() { if (!fledasty_utf8_string_validate(invalid_utf8, 2)) { printf("UTF-8 invalid string is invalid!\n"); } - + + fledasty_utf8_string_clear(&test_utf8_string); if (fledasty_utf8_string_is_empty(&test_utf8_string)) { printf("UTF-8 string is empty!\n"); }