diff --git a/include/arc/console/key.h b/include/arc/console/key.h index 39c3236..c2265c6 100644 --- a/include/arc/console/key.h +++ b/include/arc/console/key.h @@ -54,6 +54,8 @@ typedef enum ARC_ConsoleKey_Key { ARC_KEY_DOWN, ARC_KEY_UP, + ARC_KEY_BACKSPACE, + ARC_KEY_ESC } ARC_ConsoleKey_Key; @@ -73,4 +75,4 @@ uint8_t ARC_ConsoleKey_GetCharFromKey(ARC_ConsoleKey *consoleKey); } #endif -#endif // !ARC_CONSOLE_KEY_H_ \ No newline at end of file +#endif // !ARC_CONSOLE_KEY_H_ diff --git a/include/arc/std/string.h b/include/arc/std/string.h index 3fe80e2..53c6b94 100644 --- a/include/arc/std/string.h +++ b/include/arc/std/string.h @@ -78,6 +78,35 @@ void ARC_String_ReplaceWithSubstring(ARC_String **string, uint64_t start, uint64 */ void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, ARC_String *substring); +/** + * @brief appends to an ARC_String with an ARC_String + * + * @note this uses ARC_String_AppendCString, so debug logs will be thrown in that function not this one + * + * @param string the string to add to, will not change on error + * @param append the string that will be added to the back of string +*/ +void ARC_String_Append(ARC_String **string, ARC_String *append); + +/** + * @brief appends to an ARC_String with an ARC_String + * + * @param string the string to add to, will not change on error + * @param cstring the cstring that will be added to the back of string + * @param length the length of the cstring that is being added +*/ +void ARC_String_AppendCString(ARC_String **string, const char *cstring, uint64_t length); + +/** + * @brief appends to an ARC_String with an ARC_String + * + * @note this uses ARC_String_AppendCString, so debug logs will be thrown in that function not this one + * + * @param string the string to add to, will not change on error + * @param cstring the cstring that will be added to the back of string +*/ +void ARC_String_AppendCStringWithStrlen(ARC_String **string, const char *cstring); + /** * @brief checks if two strings are the same * diff --git a/packages/console/ncurses/key.c b/packages/console/ncurses/key.c index 68e50f6..91226ac 100644 --- a/packages/console/ncurses/key.c +++ b/packages/console/ncurses/key.c @@ -147,6 +147,9 @@ ARC_ConsoleKey ARC_Keyboard_GetConsoleKey(enum ARC_ConsoleKey_Key key){ case ARC_KEY_RIGHT: return (ARC_ConsoleKey){ KEY_RIGHT }; + case ARC_KEY_BACKSPACE: + return (ARC_ConsoleKey){ KEY_BACKSPACE }; + //TODO: This is escape and alt, need to fix case ARC_KEY_ESC: return (ARC_ConsoleKey){ 27 }; @@ -158,4 +161,4 @@ ARC_ConsoleKey ARC_Keyboard_GetConsoleKey(enum ARC_ConsoleKey_Key key){ uint8_t ARC_ConsoleKey_GetCharFromKey(ARC_ConsoleKey *consoleKey){ return consoleKey->key; -} \ No newline at end of file +} diff --git a/src/std/string.c b/src/std/string.c index 9d12a5e..d759ad5 100644 --- a/src/std/string.c +++ b/src/std/string.c @@ -11,7 +11,9 @@ void ARC_String_Create(ARC_String **string, char *data, uint64_t length){ (*string)->data = (char *)malloc(sizeof(char) * (length + 1)); (*string)->length = length; - strncpy((*string)->data, data, length); + if(length > 0){ + strncpy((*string)->data, data, length); + } (*string)->data[length] = '\0'; } @@ -95,6 +97,27 @@ void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, AR ARC_String_RemoveSection(newString, original, index, original->length); } +void ARC_String_Append(ARC_String **string, ARC_String *append){ + ARC_String_AppendCString(string, append->data, append->length); +} + +void ARC_String_AppendCString(ARC_String **string, const char *cstring, uint64_t length){ + char *data = (char *)malloc(sizeof((*string)->length + length + 1)); + + strncpy(data, (*string)->data, (*string)->length); + strncpy(data + (*string)->length, cstring, length); + data[(*string)->length + length] = '\0'; + + free((*string)->data); + + (*string)->data = data; + (*string)->length = (*string)->length + length; +} + +void ARC_String_AppendCStringWithStrlen(ARC_String **string, const char *cstring){ + ARC_String_AppendCString(string, cstring, strlen(cstring)); +} + ARC_Bool ARC_String_Equals(ARC_String *first, ARC_String *second){ if(first->length != second->length){ return ARC_False;