fixed string class so parameters that can be stored to will allways be the first parameter, might have broken everything, need to test

This commit is contained in:
herbglitch 2024-01-16 23:58:31 -07:00
parent d64340525a
commit af9a1f1040
5 changed files with 28 additions and 28 deletions

View file

@ -169,39 +169,39 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring);
/** /**
* @brief strips the ends based on a given char * @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 * @param stripped where to store the string which has witespace stripped
* will be null if there is an error * 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 * @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 * @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 * @param stripped where to store the string which has witespace stripped
* will be null if there is an error * 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 * @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 * @param stripped where to store the string which has witespace stripped from the ends
* will be null if there is an error * 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 * @brief merges two strings together
* *
* @param combined new ARC_String of combined strings frist + second
* @param first first part of string to combine * @param first first part of string to combine
* @param second second 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 * @brief copy a subtring from a givin ARC_String

View file

@ -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_CopySubstring(&temp, current, 0, separator - 1);
ARC_String_StripEndsWhitespace(temp, &tempStripped); ARC_String_StripEndsWhitespace(&tempStripped, temp);
x = ARC_String_ToInt64_t(tempStripped); x = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped); 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_CopySubstring(&temp, current, 0, separator - 1);
ARC_String_StripEndsWhitespace(temp, &tempStripped); ARC_String_StripEndsWhitespace(&tempStripped, temp);
y = ARC_String_ToInt64_t(tempStripped); y = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped); 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_CopySubstring(&temp, current, 0, separator - 1);
ARC_String_StripEndsWhitespace(temp, &tempStripped); ARC_String_StripEndsWhitespace(&tempStripped, temp);
w = ARC_String_ToInt64_t(tempStripped); w = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped); 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_CopySubstring(&temp, current, 0, separator);
ARC_String_StripEndsWhitespace(temp, &tempStripped); ARC_String_StripEndsWhitespace(&tempStripped, temp);
h = ARC_String_ToInt64_t(tempStripped); h = ARC_String_ToInt64_t(tempStripped);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
ARC_String_Destroy(tempStripped); 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){ 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 *substr, *temp;
ARC_String_CopySubstring(&temp, stripped, index, length); ARC_String_CopySubstring(&temp, stripped, index, length);
ARC_String_StripEndsWhitespace(temp, &substr); ARC_String_StripEndsWhitespace(&substr, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
// reading in reference // 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 *temp, *stripped;
ARC_String_CopySubstring(&temp, string, 1, string->length - 2); ARC_String_CopySubstring(&temp, string, 1, string->length - 2);
ARC_String_StripEndsWhitespace(temp, &stripped); ARC_String_StripEndsWhitespace(&stripped, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
uint64_t arraySize = 1; uint64_t arraySize = 1;

View file

@ -195,7 +195,7 @@ void ARC_Config_SetKeyGroup(ARC_Config *config, ARC_String **data, uint8_t *comm
ARC_String *name, *temp; ARC_String *name, *temp;
ARC_String_CopySubstring(&temp, *data, index, nextIndex - index - 1); ARC_String_CopySubstring(&temp, *data, index, nextIndex - index - 1);
ARC_String_StripEndsWhitespace(temp, &name); ARC_String_StripEndsWhitespace(&name, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
temp = *data; temp = *data;
@ -258,11 +258,11 @@ void ARC_Config_GetNameAndValue(ARC_String *data, ARC_String **name, ARC_String
index++; index++;
ARC_String *dataTemp = *name; ARC_String *dataTemp = *name;
ARC_String_StripEndsWhitespace(dataTemp, name); ARC_String_StripEndsWhitespace(name, dataTemp);
ARC_String_Destroy(dataTemp); ARC_String_Destroy(dataTemp);
ARC_String_CopySubstring(&dataTemp, data, index, data->length - index); ARC_String_CopySubstring(&dataTemp, data, index, data->length - index);
ARC_String_StripEndsWhitespace(dataTemp, value); ARC_String_StripEndsWhitespace(value, dataTemp);
ARC_String_Destroy(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){ while(*data && (*data)->length){
ARC_String *dataTemp = *data; ARC_String *dataTemp = *data;
ARC_String_StripEndsWhitespace(dataTemp, data); ARC_String_StripEndsWhitespace(data, dataTemp);
ARC_String_Destroy(dataTemp); ARC_String_Destroy(dataTemp);
// break out of current group // 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 *keyType, *keyTypeTemp;
ARC_String_CopySubstring(&keyTypeTemp, *data, 0, index); ARC_String_CopySubstring(&keyTypeTemp, *data, 0, index);
ARC_String_StripEndsWhitespace(keyTypeTemp, &keyType); ARC_String_StripEndsWhitespace(&keyType, keyTypeTemp);
ARC_String_Destroy(keyTypeTemp); ARC_String_Destroy(keyTypeTemp);
if(ARC_String_EqualsCString(keyType, "group", 5)){ 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 *commandArgTemp, *commandArg;
ARC_String_CopySubstring(&commandArgTemp, command, index + space->length, command->length - (index + space->length)); 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); ARC_String_Destroy(commandArgTemp);
if(ARC_String_EqualsCString(command, "load", 4)){ 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); ARC_String_Destroy(temp);
temp = data; temp = data;
ARC_String_StripEndsWhitespace(temp, &data); ARC_String_StripEndsWhitespace(&data, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
ARC_Config_Recurse(config, &data, NULL, &command); ARC_Config_Recurse(config, &data, NULL, &command);

View file

@ -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){ 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 *substr, *temp;
ARC_String_CopySubstring(&temp, stripped, index, length); ARC_String_CopySubstring(&temp, stripped, index, length);
ARC_String_StripEndsWhitespace(temp, &substr); ARC_String_StripEndsWhitespace(&substr, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
// reading in reference // 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 *temp, *stripped;
ARC_String_CopySubstring(&temp, string, 1, string->length - 2); ARC_String_CopySubstring(&temp, string, 1, string->length - 2);
ARC_String_StripEndsWhitespace(temp, &stripped); ARC_String_StripEndsWhitespace(&stripped, temp);
ARC_String_Destroy(temp); ARC_String_Destroy(temp);
uint64_t arraySize = 1; uint64_t arraySize = 1;

View file

@ -204,7 +204,7 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){
return ~(uint64_t)0; 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){ if(!original){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
*stripped = 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); 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){ if(!original){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
*stripped = NULL; *stripped = NULL;
@ -318,7 +318,7 @@ void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped){
ARC_String_Create(stripped, data, length); 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; uint64_t index;
for(uint64_t i = 0; i < original->length; i++){ for(uint64_t i = 0; i < original->length; i++){
if(original->data[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); 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]; char data[first->length + second->length];
for(uint32_t i = 0; i < first->length; i++){ for(uint32_t i = 0; i < first->length; i++){
data[i] = first->data[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(&first , original, 0 , removeIndex );
ARC_String_CopySubstring(&second, original, removeIndex + removeLength, original->length - (removeIndex + removeLength)); 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(first );
ARC_String_Destroy(second); ARC_String_Destroy(second);