This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YimMenu/src/gta/joaat.hpp
Andreas Maerten e07601347d refactor: switch RAGE_JOAAT with string literal functions (#2806)
Why? Shorter to write and removes the macro usage

I used the following regex to find all occurrences:
```r
RAGE_JOAAT\("(.*?)"\)
```
then the following to replace it all:
```r
"$1"_J
```
2024-03-12 09:42:11 +01:00

53 lines
971 B
C++

#pragma once
#include "rage/joaat.hpp"
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <type_traits>
inline consteval char consteval_to_lower(char c)
{
return c >= 'A' && c <= 'Z' ? c | 1 << 5 : c;
}
namespace rage
{
inline constexpr joaat_t constexpr_joaat(const std::string_view s)
{
joaat_t result = 0;
for (std::size_t i = 0; i < s.size(); i++)
{
result += joaat_to_lower(s[i]);
result += (result << 10);
result ^= (result >> 6);
}
result += (result << 3);
result ^= (result >> 11);
result += (result << 15);
return result;
}
}
inline consteval rage::joaat_t operator""_J(const char* s, std::size_t n)
{
rage::joaat_t result = 0;
for (std::size_t i = 0; i < n; i++)
{
result += consteval_to_lower(s[i]);
result += (result << 10);
result ^= (result >> 6);
}
result += (result << 3);
result ^= (result >> 11);
result += (result << 15);
return result;
}
static_assert("test"_J == 0x3f75ccc1);