feat(string): implemented clear and is empty function
This commit is contained in:
parent
c9c8e8a95f
commit
267fe05297
3 changed files with 21 additions and 1 deletions
|
|
@ -49,4 +49,8 @@ FledastyError fledasty_string_remove_range(FledastyString *current_string, const
|
|||
|
||||
FledastyError fledasty_string_replace_string(FledastyString *current_string, char *replace_character_string, const size_t replace_character_string_size, char *character_string, const size_t character_string_size);
|
||||
|
||||
FledastyError fledasty_string_clear(FledastyString *current_string);
|
||||
|
||||
static inline bool fledasty_string_is_empty(const FledastyString *current_string) { return current_string == NULL || current_string->size == 0; }
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -237,3 +237,14 @@ FledastyError fledasty_string_replace_string(FledastyString *current_string, cha
|
|||
|
||||
return FLEDASTY_ERROR_VALUE_NOT_FOUND;
|
||||
}
|
||||
|
||||
FledastyError fledasty_string_clear(FledastyString *current_string) {
|
||||
if (current_string == NULL) {
|
||||
return FLEDASTY_ERROR_INVALID_POINTER;
|
||||
}
|
||||
|
||||
current_string->size = 0;
|
||||
current_string->character_string[0] = '\0';
|
||||
|
||||
return FLEDASTY_ERROR_NONE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,6 +302,11 @@ int main() {
|
|||
fledasty_string_replace_string(&normal_test_string, "Hello", 5, "Goodbye", 7);
|
||||
printf("Replace: %s\n", normal_test_string.character_string);
|
||||
|
||||
fledasty_string_clear(&normal_test_string);
|
||||
if (fledasty_string_is_empty(&normal_test_string)) {
|
||||
printf("String is empty!\n");
|
||||
}
|
||||
|
||||
fledasty_string_free(&normal_test_string);
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue