From d64340525a2c0b5a4976a1a6de9608273d1a31c3 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 15 Jan 2024 02:14:35 -0700 Subject: [PATCH] added a few functions to string and added some logs to string --- include/arc/std/string.h | 12 ++++++++++++ src/std/string.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/arc/std/string.h b/include/arc/std/string.h index 1a604c9..91c9b40 100644 --- a/include/arc/std/string.h +++ b/include/arc/std/string.h @@ -87,6 +87,18 @@ uint8_t ARC_String_Equals(ARC_String *first, ARC_String *second); */ uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length); +/** + * @brief check if ARC_String and cstring match + * + * @param string ARC_string to check + * @param offset postion based on string to start comparing against cstring + * @param cstring cstring to check + * @param length length of cstring + * + * @return 1 if match, 0 if they don't match +*/ +uint8_t ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length); + /** * @brief checks if string is alphabetic * diff --git a/src/std/string.c b/src/std/string.c index fe29aa5..8759fa7 100644 --- a/src/std/string.c +++ b/src/std/string.c @@ -100,6 +100,18 @@ uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64 return 1; } +uint8_t ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length){ + if(string->length - offset < length){ + return 0; + } + + if(strncmp(string->data + offset, cstring, length)){ + return 0; + } + + return 1; +} + uint8_t ARC_String_Alpha(ARC_String *string){ for(uint64_t length = string->length; length; length--){ if(string->data[length - 1] >= 'a' && string->data[length - 1] <= 'z'){ @@ -131,6 +143,7 @@ double ARC_String_ToDouble(ARC_String *string){ uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){ if(!string || !substring){ + ARC_DEBUG_ERR("ARC_String_Find(string, substring), string or substring was null"); arc_errno = ARC_ERRNO_NULL; return ~(uint64_t)0; } @@ -152,6 +165,7 @@ uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){ uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length){ if(!string || !cstring){ arc_errno = ARC_ERRNO_NULL; + ARC_DEBUG_ERR("ARC_String_FindCString(string, cstring, length), string or cstring was null"); return ~(uint64_t)0; } @@ -172,6 +186,7 @@ uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){ if(!string || !substring){ arc_errno = ARC_ERRNO_NULL; + ARC_DEBUG_ERR("ARC_String_FindBack(string, substring), string or substring was null"); return ~(uint64_t)0; }