feat(string): implemented append function

This commit is contained in:
Mineplay 2025-07-11 06:14:40 -05:00
parent 8714361e85
commit c64a4a2011
3 changed files with 26 additions and 0 deletions

View file

@ -38,4 +38,6 @@ typedef struct {
FledastyError fledasty_string_free(FledastyString *current_string);
FledastyError fledasty_string_append(FledastyString *current_string, char *character_string, const size_t character_string_size);
#endif

View file

@ -41,3 +41,25 @@ FledastyError fledasty_string_free(FledastyString *current_string) {
current_string->character_string = NULL;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_string_append(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;
}
if (current_string->capacity <= current_string->size + character_string_size) {
current_string->capacity += (current_string->capacity > character_string_size) ? current_string->capacity : character_string_size + 1;
current_string->character_string = (char*)hallocy_realloc(current_string->character_string, current_string->capacity * sizeof(unsigned char));
if (current_string->character_string == NULL) {
return FLEDASTY_ERROR_FAILED_ALLOCATION;
}
}
hallocy_copy_memory(current_string->character_string + current_string->size, character_string, character_string_size);
current_string->size += character_string_size;
current_string->character_string[current_string->size] = '\0';
return FLEDASTY_ERROR_NONE;
}

View file

@ -284,6 +284,8 @@ int main() {
fledasty_utf8_string_free(&test_utf8_string);
FledastyString normal_test_string = { 0, 0, NULL };
fledasty_string_append(&normal_test_string, "Testing", 7);
printf("%s\n", normal_test_string.character_string);
fledasty_string_free(&normal_test_string);
printf("Done\n");