feat(string): implemented append function
This commit is contained in:
parent
8714361e85
commit
c64a4a2011
3 changed files with 26 additions and 0 deletions
|
|
@ -38,4 +38,6 @@ typedef struct {
|
||||||
|
|
||||||
FledastyError fledasty_string_free(FledastyString *current_string);
|
FledastyError fledasty_string_free(FledastyString *current_string);
|
||||||
|
|
||||||
|
FledastyError fledasty_string_append(FledastyString *current_string, char *character_string, const size_t character_string_size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,25 @@ FledastyError fledasty_string_free(FledastyString *current_string) {
|
||||||
current_string->character_string = NULL;
|
current_string->character_string = NULL;
|
||||||
return FLEDASTY_ERROR_NONE;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -284,6 +284,8 @@ int main() {
|
||||||
fledasty_utf8_string_free(&test_utf8_string);
|
fledasty_utf8_string_free(&test_utf8_string);
|
||||||
|
|
||||||
FledastyString normal_test_string = { 0, 0, NULL };
|
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);
|
fledasty_string_free(&normal_test_string);
|
||||||
printf("Done\n");
|
printf("Done\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue