diff --git a/Include/Fledasty/Strings/UTF8String.h b/Include/Fledasty/Strings/UTF8String.h index e887367..10526a5 100644 --- a/Include/Fledasty/Strings/UTF8String.h +++ b/Include/Fledasty/Strings/UTF8String.h @@ -44,6 +44,7 @@ FledastyError fledasty_utf8_string_insert_after_string(FledastyUtf8String *curre FledastyError fledasty_utf8_string_pop(FledastyUtf8String *current_string); FledastyError fledasty_utf8_string_remove(FledastyUtf8String *current_string, unsigned char *character_string, size_t character_string_size); +FledastyError fledasty_utf8_string_remove_range(FledastyUtf8String *current_string, size_t start_index, size_t end_index); 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 d6e7bb4..eda8264 100644 --- a/Src/Strings/UTF8String.c +++ b/Src/Strings/UTF8String.c @@ -222,6 +222,21 @@ FledastyError fledasty_utf8_string_remove(FledastyUtf8String *current_string, un return FLEDASTY_ERROR_NONE; } +FledastyError fledasty_utf8_string_remove_range(FledastyUtf8String *current_string, size_t start_index, size_t end_index) { + if (current_string == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + if (start_index > end_index || end_index > current_string->size) { + return FLEDASTY_ERROR_INDEX_OUT_OF_RANGE; + } + + hallocy_move_memory(current_string->character_string + start_index, current_string->character_string + end_index, current_string->size - end_index); + current_string->size -= end_index - start_index; + + return FLEDASTY_ERROR_NONE; +} + FledastyError fledasty_utf8_string_clear(FledastyUtf8String *current_string) { if (current_string == NULL) { return FLEDASTY_ERROR_INVALID_POINTER; diff --git a/Tests/Main.c b/Tests/Main.c index 5c4ecd9..963c553 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -243,6 +243,8 @@ int main() { printf("Pop: %s\n", test_utf8_string.character_string); fledasty_utf8_string_remove(&test_utf8_string, (unsigned char*)"𓃶 ", 5); printf("Remove: %s\n", test_utf8_string.character_string); + fledasty_utf8_string_remove_range(&test_utf8_string, 0, 5); + printf("Remove range: %s\n", test_utf8_string.character_string); if (fledasty_utf8_string_has_string(&test_utf8_string, (unsigned char*)"😀", 4)) { printf("String contains 😀!\n");