diff options
Diffstat (limited to 'source/core/slang-string.h')
| -rw-r--r-- | source/core/slang-string.h | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 65fd3a315..3f401b7bb 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -10,8 +10,10 @@ #include "slang-common.h" #include "slang-hash.h" #include "slang-secure-crt.h" +#include "slang-stable-hash.h" #include <new> +#include <type_traits> namespace Slang { @@ -32,8 +34,10 @@ namespace Slang } } template<typename IntType> - inline int intToAscii(char* buffer, IntType val, int radix) + inline int intToAscii(char* buffer, IntType val, int radix, int padTo = 0) { + static_assert(std::is_integral_v<IntType>); + int i = 0; IntType sign; @@ -52,6 +56,9 @@ namespace Slang buffer[i++] = (char)(digit - 10 + 'A'); } while ((val /= radix) > 0); + while(i < padTo) + buffer[i++] = '0'; + if (sign < 0) buffer[i++] = '-'; @@ -189,7 +196,8 @@ namespace Slang /// Trims any horizonatl whitespace from start and returns as a substring UnownedStringSlice trimStart() const; - HashCode getHashCode() const + static constexpr bool kHasUniformHash = true; + HashCode64 getHashCode() const { return Slang::getHashCode(m_begin, size_t(m_end - m_begin)); } @@ -508,6 +516,10 @@ namespace Slang void append(float val, const char* format = "%g"); void append(double val, const char* format = "%g"); + // Padded hex representations + void append(StableHashCode32 val); + void append(StableHashCode64 val); + void append(char const* str); void append(char const* str, size_t len); void append(const char* textBegin, char const* textEnd); @@ -549,6 +561,14 @@ namespace Slang { append(val, radix); } + explicit String(StableHashCode32 val) + { + append(val); + } + explicit String(StableHashCode64 val) + { + append(val); + } explicit String(float val, const char* format = "%g") { append(val, format); @@ -869,7 +889,8 @@ namespace Slang return contains(str.begin()); } - HashCode getHashCode() const + static constexpr bool kHasUniformHash = true; + HashCode64 getHashCode() const { return Slang::getHashCode(StringRepresentation::asSlice(m_buffer)); } |
