From 062d10805f7d1b64bb29c506cc0a3b3ca864170c Mon Sep 17 00:00:00 2001 From: Mineplay Date: Mon, 12 May 2025 05:56:18 -0500 Subject: [PATCH] feat(utf-8 string): implemented is empty function --- Include/Fledasty/Core/DoublyLinkedList.h | 2 +- Include/Fledasty/Core/DynamicArray.h | 2 +- Include/Fledasty/Core/HashTable.h | 2 +- Include/Fledasty/Core/LinkedList.h | 2 +- Include/Fledasty/Core/Queue.h | 2 +- Include/Fledasty/Core/Stack.h | 2 +- Include/Fledasty/Strings/UTF8String.h | 8 +++++--- Src/Strings/UTF8String.c | 4 ++-- Tests/Main.c | 4 ++++ 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Include/Fledasty/Core/DoublyLinkedList.h b/Include/Fledasty/Core/DoublyLinkedList.h index c588131..f5ac708 100644 --- a/Include/Fledasty/Core/DoublyLinkedList.h +++ b/Include/Fledasty/Core/DoublyLinkedList.h @@ -55,6 +55,6 @@ FledastyError fledasty_doubly_linked_list_remove_value(FledastyDoublyLinkedList FledastyError fledasty_doubly_linked_list_clear(FledastyDoublyLinkedList *current_doubly_linked_list); bool fledasty_doubly_linked_list_has_value(const FledastyDoublyLinkedList *current_doubly_linked_list, void *value); -static inline bool fledasty_doubly_linked_list_is_empty(const FledastyDoublyLinkedList *current_doubly_linked_list) { return current_doubly_linked_list->size == 0; } +static inline bool fledasty_doubly_linked_list_is_empty(const FledastyDoublyLinkedList *current_doubly_linked_list) { return current_doubly_linked_list == NULL || current_doubly_linked_list->size == 0; } #endif \ No newline at end of file diff --git a/Include/Fledasty/Core/DynamicArray.h b/Include/Fledasty/Core/DynamicArray.h index 1f64b18..a58098a 100644 --- a/Include/Fledasty/Core/DynamicArray.h +++ b/Include/Fledasty/Core/DynamicArray.h @@ -53,6 +53,6 @@ FledastyError fledasty_dynamic_array_remove_value(FledastyDynamicArray *current_ FledastyError fledasty_dynamic_array_clear(FledastyDynamicArray *current_dynamic_array); bool fledasty_dynamic_array_has_value(const FledastyDynamicArray *current_dynamic_array, void *value); -inline static bool fledasty_dynamic_array_is_empty(const FledastyDynamicArray *current_dynamic_array) { return current_dynamic_array->size == 0; } +inline static bool fledasty_dynamic_array_is_empty(const FledastyDynamicArray *current_dynamic_array) { return current_dynamic_array == NULL || current_dynamic_array->size == 0; } #endif diff --git a/Include/Fledasty/Core/HashTable.h b/Include/Fledasty/Core/HashTable.h index 1ccd35b..e1d0b30 100644 --- a/Include/Fledasty/Core/HashTable.h +++ b/Include/Fledasty/Core/HashTable.h @@ -53,6 +53,6 @@ FledastyError fledasty_hash_table_remove(FledastyHashTable *current_hash_table, FledastyError fledasty_hash_table_clear(FledastyHashTable *current_hash_table); bool fledasty_hash_table_has_key(const FledastyHashTable *current_hash_table, void *key); -static inline bool fledasty_hash_table_is_empty(const FledastyHashTable *current_hash_table) { return current_hash_table->size == 0; } +static inline bool fledasty_hash_table_is_empty(const FledastyHashTable *current_hash_table) { return current_hash_table == NULL || current_hash_table->size == 0; } #endif \ No newline at end of file diff --git a/Include/Fledasty/Core/LinkedList.h b/Include/Fledasty/Core/LinkedList.h index 7505a73..49f5bc7 100644 --- a/Include/Fledasty/Core/LinkedList.h +++ b/Include/Fledasty/Core/LinkedList.h @@ -54,6 +54,6 @@ FledastyError fledasty_linked_list_remove_value(FledastyLinkedList *current_link FledastyError fledasty_linked_list_clear(FledastyLinkedList *current_linked_list); bool fledasty_linked_list_has_value(const FledastyLinkedList *current_linked_list, void *value); -static inline bool fledasty_linked_list_is_empty(const FledastyLinkedList *current_linked_list) { return current_linked_list->size == 0; } +static inline bool fledasty_linked_list_is_empty(const FledastyLinkedList *current_linked_list) { return current_linked_list == NULL || current_linked_list->size == 0; } #endif diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index 9a4b16a..ab9f472 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -45,6 +45,6 @@ void *fledasty_queue_pop(FledastyQueue *current_queue); FledastyError fledasty_queue_clear(FledastyQueue *current_queue); -static inline bool fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue->size == 0; } +static inline bool fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue == NULL || current_queue->size == 0; } #endif diff --git a/Include/Fledasty/Core/Stack.h b/Include/Fledasty/Core/Stack.h index bd17de3..cbee423 100644 --- a/Include/Fledasty/Core/Stack.h +++ b/Include/Fledasty/Core/Stack.h @@ -44,6 +44,6 @@ void *fledasty_stack_pop(FledastyStack *current_stack); FledastyError fledasty_stack_clear(FledastyStack *current_stack); -static inline bool fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack->size == 0; } +static inline bool fledasty_stack_is_empty(const FledastyStack *current_stack) { return current_stack == NULL || current_stack->size == 0; } #endif diff --git a/Include/Fledasty/Strings/UTF8String.h b/Include/Fledasty/Strings/UTF8String.h index ecd8391..43aef64 100644 --- a/Include/Fledasty/Strings/UTF8String.h +++ b/Include/Fledasty/Strings/UTF8String.h @@ -42,7 +42,9 @@ 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_length, unsigned char *character_string, size_t character_string_length); FledastyError fledasty_utf8_string_insert_at_index(FledastyUtf8String *current_string, size_t index, unsigned char *character_string, size_t character_string_length); -FledastyUtf8String fledasty_utf8_string_encode(uint32_t *unicode, const size_t size); -uint32_t *fledasty_utf8_string_decode(FledastyUtf8String *current_string, size_t *unicode_string_length); +static inline bool fledasty_utf8_string_is_empty(const FledastyUtf8String *current_string) { return current_string == NULL || current_string->size == 0; } -bool fledasty_utf8_string_validate(unsigned char *character_string, const size_t character_string_length); +FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const size_t size); +uint32_t *fledasty_utf8_string_decode(const FledastyUtf8String *current_string, size_t *unicode_string_length); + +bool fledasty_utf8_string_validate(unsigned char *character_string, const size_t character_string_length); \ No newline at end of file diff --git a/Src/Strings/UTF8String.c b/Src/Strings/UTF8String.c index 401cb7a..ea0bf71 100644 --- a/Src/Strings/UTF8String.c +++ b/Src/Strings/UTF8String.c @@ -181,7 +181,7 @@ FledastyError fledasty_utf8_string_insert_at_index(FledastyUtf8String *current_s return FLEDASTY_ERROR_NONE; } -FledastyUtf8String fledasty_utf8_string_encode(uint32_t *unicode, const size_t size) { +FledastyUtf8String fledasty_utf8_string_encode(const uint32_t *unicode, const size_t size) { FledastyUtf8String utf8_string; fledasty_utf8_string_initialize(&utf8_string, NULL, 0); @@ -242,7 +242,7 @@ FledastyUtf8String fledasty_utf8_string_encode(uint32_t *unicode, const size_t s return utf8_string; } -uint32_t *fledasty_utf8_string_decode(FledastyUtf8String *current_string, size_t *unicode_string_length) { +uint32_t *fledasty_utf8_string_decode(const FledastyUtf8String *current_string, size_t *unicode_string_length) { if (current_string == NULL || unicode_string_length == NULL) { return NULL; } diff --git a/Tests/Main.c b/Tests/Main.c index 89091ab..96a0f55 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -259,6 +259,10 @@ int main() { printf("UTF-8 invalid string is invalid!\n"); } + if (fledasty_utf8_string_is_empty(&test_utf8_string)) { + printf("UTF-8 string is empty!\n"); + } + hallocy_free(invalid_utf8); hallocy_free(unicode); fledasty_utf8_string_destroy(&encoded_string);