From af9a1f1040e60a663e175a3b36d752913941b973 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Tue, 16 Jan 2024 23:58:31 -0700 Subject: [PATCH] fixed string class so parameters that can be stored to will allways be the first parameter, might have broken everything, need to test --- include/arc/std/string.h | 16 ++++++++-------- src/math/config.c | 12 ++++++------ src/std/config.c | 14 +++++++------- src/std/defaults/config.c | 4 ++-- src/std/string.c | 10 +++++----- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/arc/std/string.h b/include/arc/std/string.h index 91c9b40..bc7b02d 100644 --- a/include/arc/std/string.h +++ b/include/arc/std/string.h @@ -169,39 +169,39 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring); /** * @brief strips the ends based on a given char * - * @param original the string which whill have the matching char stripped from * @param stripped where to store the string which has witespace stripped * will be null if there is an error + * @param original the string which whill have the matching char stripped from * @param charToStrip the char that will be stripped from the ends */ -void ARC_String_StripEnds(ARC_String *original, ARC_String **stripped, char charToStrip); +void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip); /** * @brief strips whitespace from a ARC_String * - * @param original the string which whill have whitespace stripped from * @param stripped where to store the string which has witespace stripped * will be null if there is an error + * @param original the string which whill have whitespace stripped from */ -void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped); +void ARC_String_StripWhitespace(ARC_String **stripped, ARC_String *original); /** * @brief strips the whitespace from the ends of a string * - * @param original the string which whill have the whitespace stripped from its ends * @param stripped where to store the string which has witespace stripped from the ends * will be null if there is an error + * @param original the string which whill have the whitespace stripped from its ends */ -void ARC_String_StripEndsWhitespace(ARC_String *original, ARC_String **stripped); +void ARC_String_StripEndsWhitespace(ARC_String **stripped, ARC_String *original); /** * @brief merges two strings together * + * @param combined new ARC_String of combined strings frist + second * @param first first part of string to combine * @param second second part of string to combine - * @param combined new ARC_String of combined strings frist + second */ -void ARC_String_Merge(ARC_String *first, ARC_String *second, ARC_String **combined); +void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second); /** * @brief copy a subtring from a givin ARC_String diff --git a/src/math/config.c b/src/math/config.c index 11c0214..2e48868 100644 --- a/src/math/config.c +++ b/src/math/config.c @@ -85,7 +85,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){ } ARC_String_CopySubstring(&temp, current, 0, separator - 1); - ARC_String_StripEndsWhitespace(temp, &tempStripped); + ARC_String_StripEndsWhitespace(&tempStripped, temp); x = ARC_String_ToInt64_t(tempStripped); ARC_String_Destroy(temp); ARC_String_Destroy(tempStripped); @@ -101,7 +101,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){ } ARC_String_CopySubstring(&temp, current, 0, separator - 1); - ARC_String_StripEndsWhitespace(temp, &tempStripped); + ARC_String_StripEndsWhitespace(&tempStripped, temp); y = ARC_String_ToInt64_t(tempStripped); ARC_String_Destroy(temp); ARC_String_Destroy(tempStripped); @@ -117,7 +117,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){ } ARC_String_CopySubstring(&temp, current, 0, separator - 1); - ARC_String_StripEndsWhitespace(temp, &tempStripped); + ARC_String_StripEndsWhitespace(&tempStripped, temp); w = ARC_String_ToInt64_t(tempStripped); ARC_String_Destroy(temp); ARC_String_Destroy(tempStripped); @@ -133,7 +133,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){ } ARC_String_CopySubstring(&temp, current, 0, separator); - ARC_String_StripEndsWhitespace(temp, &tempStripped); + ARC_String_StripEndsWhitespace(&tempStripped, temp); h = ARC_String_ToInt64_t(tempStripped); ARC_String_Destroy(temp); ARC_String_Destroy(tempStripped); @@ -150,7 +150,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){ void ARC_RectArray_ReadRect(ARC_Config* config, ARC_String *stripped, uint64_t index, uint64_t length, uint64_t *arrayIndex, void **value){ ARC_String *substr, *temp; ARC_String_CopySubstring(&temp, stripped, index, length); - ARC_String_StripEndsWhitespace(temp, &substr); + ARC_String_StripEndsWhitespace(&substr, temp); ARC_String_Destroy(temp); // reading in reference @@ -194,7 +194,7 @@ uint8_t ARC_RectArray_Read(ARC_Config* config, ARC_String *string, void **value) ARC_String *temp, *stripped; ARC_String_CopySubstring(&temp, string, 1, string->length - 2); - ARC_String_StripEndsWhitespace(temp, &stripped); + ARC_String_StripEndsWhitespace(&stripped, temp); ARC_String_Destroy(temp); uint64_t arraySize = 1; diff --git a/src/std/config.c b/src/std/config.c index b8c91c7..78b294a 100644 --- a/src/std/config.c +++ b/src/std/config.c @@ -195,7 +195,7 @@ void ARC_Config_SetKeyGroup(ARC_Config *config, ARC_String **data, uint8_t *comm ARC_String *name, *temp; ARC_String_CopySubstring(&temp, *data, index, nextIndex - index - 1); - ARC_String_StripEndsWhitespace(temp, &name); + ARC_String_StripEndsWhitespace(&name, temp); ARC_String_Destroy(temp); temp = *data; @@ -258,11 +258,11 @@ void ARC_Config_GetNameAndValue(ARC_String *data, ARC_String **name, ARC_String index++; ARC_String *dataTemp = *name; - ARC_String_StripEndsWhitespace(dataTemp, name); + ARC_String_StripEndsWhitespace(name, dataTemp); ARC_String_Destroy(dataTemp); ARC_String_CopySubstring(&dataTemp, data, index, data->length - index); - ARC_String_StripEndsWhitespace(dataTemp, value); + ARC_String_StripEndsWhitespace(value, dataTemp); ARC_String_Destroy(dataTemp); } @@ -276,7 +276,7 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group while(*data && (*data)->length){ ARC_String *dataTemp = *data; - ARC_String_StripEndsWhitespace(dataTemp, data); + ARC_String_StripEndsWhitespace(data, dataTemp); ARC_String_Destroy(dataTemp); // break out of current group @@ -302,7 +302,7 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group ARC_String *keyType, *keyTypeTemp; ARC_String_CopySubstring(&keyTypeTemp, *data, 0, index); - ARC_String_StripEndsWhitespace(keyTypeTemp, &keyType); + ARC_String_StripEndsWhitespace(&keyType, keyTypeTemp); ARC_String_Destroy(keyTypeTemp); if(ARC_String_EqualsCString(keyType, "group", 5)){ @@ -468,7 +468,7 @@ void ARC_Config_RunCommand(ARC_Config *config, ARC_String *command){ ARC_String *commandArgTemp, *commandArg; ARC_String_CopySubstring(&commandArgTemp, command, index + space->length, command->length - (index + space->length)); - ARC_String_StripWhitespace(commandArgTemp, &commandArg); + ARC_String_StripWhitespace(&commandArg, commandArgTemp); ARC_String_Destroy(commandArgTemp); if(ARC_String_EqualsCString(command, "load", 4)){ @@ -548,7 +548,7 @@ void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command){ ARC_String_Destroy(temp); temp = data; - ARC_String_StripEndsWhitespace(temp, &data); + ARC_String_StripEndsWhitespace(&data, temp); ARC_String_Destroy(temp); ARC_Config_Recurse(config, &data, NULL, &command); diff --git a/src/std/defaults/config.c b/src/std/defaults/config.c index 844f988..f6304b6 100644 --- a/src/std/defaults/config.c +++ b/src/std/defaults/config.c @@ -196,7 +196,7 @@ uint8_t ARC_ConfigKey_Read_String(ARC_Config* config, ARC_String *string, void * void ARC_ConfigKey_StringArray_ReadString(ARC_Config* config, ARC_String *stripped, uint64_t index, uint64_t length, uint64_t *arrayIndex, void **value){ ARC_String *substr, *temp; ARC_String_CopySubstring(&temp, stripped, index, length); - ARC_String_StripEndsWhitespace(temp, &substr); + ARC_String_StripEndsWhitespace(&substr, temp); ARC_String_Destroy(temp); // reading in reference @@ -239,7 +239,7 @@ uint8_t ARC_ConfigKey_Read_StringArray(ARC_Config* config, ARC_String *string, v ARC_String *temp, *stripped; ARC_String_CopySubstring(&temp, string, 1, string->length - 2); - ARC_String_StripEndsWhitespace(temp, &stripped); + ARC_String_StripEndsWhitespace(&stripped, temp); ARC_String_Destroy(temp); uint64_t arraySize = 1; diff --git a/src/std/string.c b/src/std/string.c index 8759fa7..bee9680 100644 --- a/src/std/string.c +++ b/src/std/string.c @@ -204,7 +204,7 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){ return ~(uint64_t)0; } -void ARC_String_StripEnds(ARC_String *original, ARC_String **stripped, char charToStrip){ +void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip){ if(!original){ arc_errno = ARC_ERRNO_NULL; *stripped = NULL; @@ -247,7 +247,7 @@ void ARC_String_StripEnds(ARC_String *original, ARC_String **stripped, char char ARC_String_Create(stripped, original->data + start, length); } -void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped){ +void ARC_String_StripWhitespace(ARC_String **stripped, ARC_String *original){ if(!original){ arc_errno = ARC_ERRNO_NULL; *stripped = NULL; @@ -318,7 +318,7 @@ void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped){ ARC_String_Create(stripped, data, length); } -void ARC_String_StripEndsWhitespace(ARC_String *original, ARC_String **stripped){ +void ARC_String_StripEndsWhitespace(ARC_String **stripped, ARC_String *original){ uint64_t index; for(uint64_t i = 0; i < original->length; i++){ if(original->data[i] == ' '){ @@ -366,7 +366,7 @@ void ARC_String_StripEndsWhitespace(ARC_String *original, ARC_String **stripped) ARC_String_CopySubstring(stripped, original, index, endIndex - index); } -void ARC_String_Merge(ARC_String *first, ARC_String *second, ARC_String **combined){ +void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second){ char data[first->length + second->length]; for(uint32_t i = 0; i < first->length; i++){ data[i] = first->data[i]; @@ -400,7 +400,7 @@ void ARC_String_RemoveSection(ARC_String **newString, ARC_String *original, uint ARC_String_CopySubstring(&first , original, 0 , removeIndex ); ARC_String_CopySubstring(&second, original, removeIndex + removeLength, original->length - (removeIndex + removeLength)); - ARC_String_Merge(first, second, newString); + ARC_String_Merge(newString, first, second); ARC_String_Destroy(first ); ARC_String_Destroy(second);