feat(utf-8 string): implemented remove function

This commit is contained in:
Mineplay 2025-05-15 10:26:32 -05:00
parent 681ca8f489
commit 15abfcffe8
3 changed files with 27 additions and 0 deletions

View file

@ -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_remove(FledastyUtf8String *current_string, unsigned char *character_string, size_t character_string_size);
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);

View file

@ -198,6 +198,30 @@ FledastyError fledasty_utf8_string_pop(FledastyUtf8String *current_string) {
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_utf8_string_remove(FledastyUtf8String *current_string, unsigned char *character_string, size_t character_string_size) {
if (current_string == NULL || character_string == NULL || character_string_size == 0) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
if (!fledasty_utf8_string_validate(character_string, character_string_size)) {
return FLEDASTY_ERROR_INVALID_VALUE;
}
size_t index = 0;
while (index < (current_string->size - character_string_size) && !hallocy_compare_memory(current_string->character_string + index, character_string, character_string_size)) {
index += 1;
}
if (index == current_string->size - character_string_size) {
return FLEDASTY_ERROR_VALUE_NOT_FOUND;
}
hallocy_move_memory(current_string->character_string + index, current_string->character_string + index + character_string_size, current_string->size - (index + character_string_size));
current_string->size -= character_string_size;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_utf8_string_clear(FledastyUtf8String *current_string) {
if (current_string == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;

View file

@ -241,6 +241,8 @@ int main() {
printf("Replace: %s\n", test_utf8_string.character_string);
fledasty_utf8_string_pop(&test_utf8_string);
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);
if (fledasty_utf8_string_has_string(&test_utf8_string, (unsigned char*)"😀", 4)) {
printf("String contains 😀!\n");