toUpper, toLower

This commit is contained in:
Timerix 2025-02-03 22:30:43 +05:00
parent 5d275c8dd1
commit 422d967165
2 changed files with 22 additions and 2 deletions

View File

@ -100,9 +100,26 @@ bool str_endsWith(str src, str fragment){
u32 str_hash32(str s){ u32 str_hash32(str s){
u8* ubuf = (u8*)s.data; u8* ubuf = (u8*)s.data;
u32 len = s.len;
u32 hash=0; 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]; hash = (hash<<6) + (hash<<16) - hash + ubuf[i];
return hash; 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;
}

View File

@ -36,3 +36,6 @@ bool str_endsWith(str src, str fragment);
/// @brief calculates string hash using sdbm32 algorythm (something like lightweight crc32) /// @brief calculates string hash using sdbm32 algorythm (something like lightweight crc32)
/// @return non-cryptografic hash of the string /// @return non-cryptografic hash of the string
u32 str_hash32(str s); u32 str_hash32(str s);
str str_toUpper(str src);
str str_toLower(str src);