mirror of
https://github.com/MonsterDruide1/OdysseyDecomp
synced 2026-04-23 09:04:21 +00:00
50 lines
1,022 B
C++
50 lines
1,022 B
C++
#include "Library/Base/HashCodeUtil.h"
|
|
|
|
#include <cctype>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
namespace al {
|
|
u32 calcHashCode(const char* str) {
|
|
if (str[0] == '\0')
|
|
return 0;
|
|
|
|
u32 hashCode = 0;
|
|
for (s32 i = 0; str[i] != '\0'; i++)
|
|
hashCode = (hashCode * 0x1f) + str[i];
|
|
|
|
return hashCode;
|
|
}
|
|
|
|
u32 calcHashCodeLower(const char* str) {
|
|
u32 hashCode = 0;
|
|
for (s32 i = 0; str[i] != '\0'; i++)
|
|
hashCode = (hashCode * 0x1f) + tolower(str[i]);
|
|
|
|
return hashCode;
|
|
}
|
|
|
|
u32 calcHashCodeFmt(const char* format, std::va_list argv) {
|
|
char buf[0x100];
|
|
vsnprintf(buf, 0x100, format, argv);
|
|
|
|
return calcHashCode(buf);
|
|
}
|
|
|
|
u32 calcHashCodeFmt(const char* format, ...) {
|
|
std::va_list argv;
|
|
|
|
va_start(argv, format);
|
|
u32 result = calcHashCodeFmt(format, argv);
|
|
va_end(argv);
|
|
|
|
return result;
|
|
}
|
|
|
|
const char* getBaseName(const char* name) {
|
|
const char* baseName = strrchr(name, '/');
|
|
|
|
return baseName != nullptr ? baseName + 1 : name;
|
|
}
|
|
} // namespace al
|