diff options
Diffstat (limited to 'MoonParser/parser.hpp')
-rw-r--r-- | MoonParser/parser.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/MoonParser/parser.hpp b/MoonParser/parser.hpp index 66d6067..cbabf06 100644 --- a/MoonParser/parser.hpp +++ b/MoonParser/parser.hpp | |||
@@ -16,6 +16,19 @@ | |||
16 | #include <codecvt> | 16 | #include <codecvt> |
17 | #include <locale> | 17 | #include <locale> |
18 | 18 | ||
19 | // const str hash helper functions | ||
20 | inline constexpr std::size_t hash(char const* input) | ||
21 | { | ||
22 | return *input ? *input + 33ull * hash(input + 1) : 5381; | ||
23 | } | ||
24 | inline std::size_t hash(const char* input, int size, int index) | ||
25 | { | ||
26 | return index < size ? input[index] + 33ull * hash(input, size, index + 1) : 5381; | ||
27 | } | ||
28 | inline std::size_t constexpr operator"" _id(const char* s, size_t) | ||
29 | { | ||
30 | return hash(s); | ||
31 | } | ||
19 | 32 | ||
20 | ///type of the parser's input. | 33 | ///type of the parser's input. |
21 | typedef std::basic_string<char32_t> input; | 34 | typedef std::basic_string<char32_t> input; |