feat(string): implemented remove function
This commit is contained in:
parent
107f8cc416
commit
719d491216
4 changed files with 27 additions and 1 deletions
|
|
@ -44,5 +44,6 @@ FledastyError fledasty_string_insert_before_string(FledastyString *current_strin
|
||||||
FledastyError fledasty_string_insert_after_string(FledastyString *current_string, char *after_character_string, const size_t after_character_string_size, char *character_string, const size_t character_string_size);
|
FledastyError fledasty_string_insert_after_string(FledastyString *current_string, char *after_character_string, const size_t after_character_string_size, char *character_string, const size_t character_string_size);
|
||||||
|
|
||||||
FledastyError fledasty_string_pop(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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -165,3 +165,25 @@ FledastyError fledasty_string_pop(FledastyString *current_string) {
|
||||||
|
|
||||||
return FLEDASTY_ERROR_NONE;
|
return FLEDASTY_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FledastyError fledasty_string_remove(FledastyString *current_string, char *character_string, const size_t character_string_size) {
|
||||||
|
if (current_string == NULL || character_string == NULL || character_string_size == 0) {
|
||||||
|
return FLEDASTY_ERROR_INVALID_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < (current_string->size - character_string_size)) {
|
||||||
|
if (hallocy_compare_memory(current_string->character_string + index, character_string, character_string_size)) {
|
||||||
|
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;
|
||||||
|
current_string->character_string[current_string->size] = '\0';
|
||||||
|
|
||||||
|
return FLEDASTY_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FLEDASTY_ERROR_VALUE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ FledastyError fledasty_utf8_string_insert_before_string(FledastyUtf8String *curr
|
||||||
|
|
||||||
current_string->size += character_string_size;
|
current_string->size += character_string_size;
|
||||||
current_string->character_string[current_string->size] = '\0';
|
current_string->character_string[current_string->size] = '\0';
|
||||||
|
|
||||||
return FLEDASTY_ERROR_NONE;
|
return FLEDASTY_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,6 +209,7 @@ FledastyError fledasty_utf8_string_remove(FledastyUtf8String *current_string, un
|
||||||
|
|
||||||
current_string->size -= character_string_size;
|
current_string->size -= character_string_size;
|
||||||
current_string->character_string[current_string->size] = '\0';
|
current_string->character_string[current_string->size] = '\0';
|
||||||
|
|
||||||
return FLEDASTY_ERROR_NONE;
|
return FLEDASTY_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -295,6 +295,8 @@ int main() {
|
||||||
printf("%s\n", normal_test_string.character_string);
|
printf("%s\n", normal_test_string.character_string);
|
||||||
fledasty_string_pop(&normal_test_string);
|
fledasty_string_pop(&normal_test_string);
|
||||||
printf("%s\n", normal_test_string.character_string);
|
printf("%s\n", normal_test_string.character_string);
|
||||||
|
fledasty_string_remove(&normal_test_string, "Bye", 3);
|
||||||
|
printf("%s\n", normal_test_string.character_string);
|
||||||
|
|
||||||
fledasty_string_free(&normal_test_string);
|
fledasty_string_free(&normal_test_string);
|
||||||
printf("Done\n");
|
printf("Done\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue