added a way to create an empty string

This commit is contained in:
herbglitch 2024-07-09 03:41:15 -06:00
parent 7f0120f0c8
commit 80331b5c34
2 changed files with 19 additions and 0 deletions

View file

@ -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); 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 * @brief destroys ARC_String type
* *

View file

@ -26,6 +26,17 @@ void ARC_String_CreateWithStrlen(ARC_String **string, char *data){
(*string)->data[(*string)->length] = '\0'; (*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){ void ARC_String_Destroy(ARC_String *string){
if(string->data){ if(string->data){
free(string->data); free(string->data);