feat(string): implemented has string function
This commit is contained in:
parent
a15cd07d38
commit
53f0763090
3 changed files with 22 additions and 1 deletions
|
|
@ -52,6 +52,7 @@ FledastyError fledasty_string_replace_string(FledastyString *current_string, cha
|
|||
FledastyError fledasty_string_clear(FledastyString *current_string);
|
||||
FledastyError fledasty_string_shrink_to_fit(FledastyString *current_string);
|
||||
|
||||
bool fledasty_string_has_string(const FledastyString *current_string, char *character_string, const size_t character_string_size);
|
||||
static inline bool fledasty_string_is_empty(const FledastyString *current_string) { return current_string == NULL || current_string->size == 0; }
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -268,6 +268,23 @@ FledastyError fledasty_string_shrink_to_fit(FledastyString *current_string) {
|
|||
if (hallocy_free(previous_string) != HALLOCY_ERROR_NONE) {
|
||||
return FLEDASTY_ERROR_FAILED_ALLOCATION;
|
||||
}
|
||||
|
||||
|
||||
return FLEDASTY_ERROR_NONE;
|
||||
}
|
||||
|
||||
bool fledasty_string_has_string(const FledastyString *current_string, char *character_string, const size_t character_string_size) {
|
||||
if (current_string == NULL || character_string == NULL || character_string_size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,6 +303,9 @@ int main() {
|
|||
printf("Replace: %s\n", normal_test_string.character_string);
|
||||
|
||||
fledasty_string_shrink_to_fit(&normal_test_string);
|
||||
if (fledasty_string_has_string(&normal_test_string, "bye", 3)) {
|
||||
printf("String contains bye!\n");
|
||||
}
|
||||
|
||||
fledasty_string_clear(&normal_test_string);
|
||||
if (fledasty_string_is_empty(&normal_test_string)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue