diff --git a/include/arc/std/string.h b/include/arc/std/string.h index 53c6b94..fc1b281 100644 --- a/include/arc/std/string.h +++ b/include/arc/std/string.h @@ -33,6 +33,14 @@ void ARC_String_Create(ARC_String **string, char *data, uint64_t length); */ void ARC_String_CreateWithStrlen(ARC_String **string, char *data); +/** + * @brief creates an empty ARC_String type, useful if you want to add to the string over time without having to keep adding to the size + * + * @param string ARC_String to create + * @param length length of ARC_String + */ +void ARC_String_CreateEmpty(ARC_String **string, uint64_t length); + /** * @brief destroys ARC_String type * diff --git a/src/std/string.c b/src/std/string.c index d759ad5..bcc9cf0 100644 --- a/src/std/string.c +++ b/src/std/string.c @@ -26,6 +26,17 @@ void ARC_String_CreateWithStrlen(ARC_String **string, char *data){ (*string)->data[(*string)->length] = '\0'; } +void ARC_String_CreateEmpty(ARC_String **string, uint64_t length){ + *string = (ARC_String *)malloc(sizeof(ARC_String)); + (*string)->data = (char *)malloc(sizeof(char) * (length + 1)); + (*string)->length = length; + + (*string)->data[0] = '\0'; + for(uint64_t index = 0; index <= length; index++){ + (*string)->data[index] = '\0'; + } +} + void ARC_String_Destroy(ARC_String *string){ if(string->data){ free(string->data);