feat(string): implemented remove range

This commit is contained in:
Mineplay 2025-07-11 06:37:26 -05:00
parent 719d491216
commit bbfca9674b
4 changed files with 29 additions and 8 deletions

View file

@ -45,5 +45,6 @@ FledastyError fledasty_string_insert_after_string(FledastyString *current_string
FledastyError fledasty_string_pop(FledastyString *current_string);
FledastyError fledasty_string_remove(FledastyString *current_string, char *character_string, const size_t character_string_size);
FledastyError fledasty_string_remove_range(FledastyString *current_string, const size_t start_index, const size_t end_index);
#endif

View file

@ -178,7 +178,7 @@ FledastyError fledasty_string_remove(FledastyString *current_string, char *chara
current_string->size -= character_string_size;
current_string->character_string[current_string->size] = '\0';
return FLEDASTY_ERROR_NONE;
}
@ -187,3 +187,20 @@ FledastyError fledasty_string_remove(FledastyString *current_string, char *chara
return FLEDASTY_ERROR_VALUE_NOT_FOUND;
}
FledastyError fledasty_string_remove_range(FledastyString *current_string, const size_t start_index, const 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;
current_string->character_string[current_string->size] = '\0';
return FLEDASTY_ERROR_NONE;
}

View file

@ -209,7 +209,7 @@ FledastyError fledasty_utf8_string_remove(FledastyUtf8String *current_string, un
current_string->size -= character_string_size;
current_string->character_string[current_string->size] = '\0';
return FLEDASTY_ERROR_NONE;
}
@ -232,6 +232,7 @@ FledastyError fledasty_utf8_string_remove_range(FledastyUtf8String *current_stri
current_string->size -= end_index - start_index;
current_string->character_string[current_string->size] = '\0';
return FLEDASTY_ERROR_NONE;
}

View file

@ -286,17 +286,19 @@ int main() {
FledastyString normal_test_string = { 0, 0, NULL };
fledasty_string_append(&normal_test_string, "Testing", 7);
printf("%s\n", normal_test_string.character_string);
printf("Append: %s\n", normal_test_string.character_string);
fledasty_string_insert_at_index(&normal_test_string, normal_test_string.size, "index", 5);
printf("%s\n", normal_test_string.character_string);
printf("Insert at index: %s\n", normal_test_string.character_string);
fledasty_string_insert_before_string(&normal_test_string, "nd", 2, "Hello", 5);
printf("%s\n", normal_test_string.character_string);
printf("Insert before: %s\n", normal_test_string.character_string);
fledasty_string_insert_after_string(&normal_test_string, "nd", 2, "Bye", 3);
printf("%s\n", normal_test_string.character_string);
printf("Insert after: %s\n", normal_test_string.character_string);
fledasty_string_pop(&normal_test_string);
printf("%s\n", normal_test_string.character_string);
printf("Pop: %s\n", normal_test_string.character_string);
fledasty_string_remove(&normal_test_string, "Bye", 3);
printf("%s\n", normal_test_string.character_string);
printf("Removed string: %s\n", normal_test_string.character_string);
fledasty_string_remove_range(&normal_test_string, 0, 6);
printf("Remove range: %s\n", normal_test_string.character_string);
fledasty_string_free(&normal_test_string);
printf("Done\n");