diff --git a/include/arc/std/string.h b/include/arc/std/string.h index a01d97d..3fe80e2 100644 --- a/include/arc/std/string.h +++ b/include/arc/std/string.h @@ -58,6 +58,17 @@ void ARC_String_Copy(ARC_String **copy, ARC_String *original); */ void ARC_String_CopySubstring(ARC_String **substring, ARC_String *original, uint64_t start, uint64_t length); +/** + * @brief replaces a string with a section of itself + * + * @note this uses ARC_String_CopySubstring so errors logs will be thrown in that function not this one + * + * @param string the string to replace, will not change on error + * @param start the starting index of the substring + * @param length the length of the substring +*/ +void ARC_String_ReplaceWithSubstring(ARC_String **string, uint64_t start, uint64_t length); + /** * @brief copy a subtring from a givin ARC_String * @@ -322,4 +333,4 @@ void ARC_String_ReplaceMatchingCStringWithStrlen(ARC_String **string, char *patt } #endif -#endif //ARC_STD_STRING_H_ \ No newline at end of file +#endif //ARC_STD_STRING_H_ diff --git a/src/std/config.c b/src/std/config.c index 78b294a..726c15f 100644 --- a/src/std/config.c +++ b/src/std/config.c @@ -583,7 +583,7 @@ void ARC_Config_CreateGroup(ARC_Config *config, ARC_String *name){ void ARC_Config_DestroyGroup(ARC_HashtableNode *group, void *userdata){ free((char *)group->key); - return ARC_Hashtable_Destroy((ARC_Hashtable *)group->data, ARC_Config_DestroyGroupNode, userdata); + ARC_Hashtable_Destroy((ARC_Hashtable *)group->data, ARC_Config_DestroyGroupNode, userdata); } void ARC_Config_DestroyGroupNode(ARC_HashtableNode *node, void *userdata){ @@ -609,4 +609,4 @@ void ARC_Config_RemoveKey(ARC_HashtableNode *node, void *userdata){ } free((ARC_ConfigKey *)node->data); -} \ No newline at end of file +} diff --git a/src/std/hashtable.c b/src/std/hashtable.c index 6c23bfc..3a6e58b 100644 --- a/src/std/hashtable.c +++ b/src/std/hashtable.c @@ -28,7 +28,7 @@ void CRC32(void *key, size_t *keysize, uint32_t *hashval){ } int8_t ARC_Default_Key_Compare(void *key1, size_t *key1size, void *key2, size_t *key2size){ - return key1 - key2; + return key1 == key2; } void ARC_HashtableNode_Create(ARC_HashtableNode **node, void *key, size_t *keysize, void *data){ diff --git a/src/std/string.c b/src/std/string.c index c1fa1da..9d12a5e 100644 --- a/src/std/string.c +++ b/src/std/string.c @@ -69,6 +69,22 @@ void ARC_String_CopySubstring(ARC_String **substring, ARC_String *original, uint ARC_String_Create(substring, data, length); } +void ARC_String_ReplaceWithSubstring(ARC_String **string, uint64_t start, uint64_t length){ + ARC_String *substring; + ARC_String_CopySubstring(&substring, *string, start, length); + + //if error or substring is null free memory and return + if(arc_errno || substring == NULL){ + if(substring != NULL){ + free(substring); + } + return; + } + + free(*string); + *string = substring; +} + void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, ARC_String *substring){ uint64_t index = ARC_String_Find(original, substring); if(arc_errno){