diff --git a/src/string/str.c b/src/string/str.c index fe3ee00..0d510cb 100644 --- a/src/string/str.c +++ b/src/string/str.c @@ -100,9 +100,26 @@ bool str_endsWith(str src, str fragment){ u32 str_hash32(str s){ u8* ubuf = (u8*)s.data; - u32 len = s.len; u32 hash=0; - for (u32 i = 0; i < len; i++) + for (u32 i = 0; i < s.len; i++) hash = (hash<<6) + (hash<<16) - hash + ubuf[i]; return hash; } + +str str_toUpper(str src){ + str r = str_copy(src); + for (u32 i = 0; i < r.len; i++){ + if(isAlphabeticalLower(r.data[i])) + r.data[i] = r.data[i] - 'a' + 'A'; + } + return r; +} + +str str_toLower(str src){ + str r = str_copy(src); + for (u32 i = 0; i < r.len; i++){ + if(isAlphabeticalUpper(r.data[i])) + r.data[i] = r.data[i] - 'A' + 'a'; + } + return r; +} diff --git a/src/string/str.h b/src/string/str.h index 6db3c66..399bad5 100644 --- a/src/string/str.h +++ b/src/string/str.h @@ -36,3 +36,6 @@ bool str_endsWith(str src, str fragment); /// @brief calculates string hash using sdbm32 algorythm (something like lightweight crc32) /// @return non-cryptografic hash of the string u32 str_hash32(str s); + +str str_toUpper(str src); +str str_toLower(str src);