diff options
| author | Stefan Boberg <[email protected]> | 2021-10-19 13:30:32 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-19 13:30:32 +0200 |
| commit | 0fe877390805272f8efe6c793ffb83e8c159d50a (patch) | |
| tree | 82752087d8c0386a6c79751fea243f6108a238b2 /zencore | |
| parent | cas: added structured manifest support (diff) | |
| parent | string: Fixed ToLower logic (needs to use unsigned arithmetic) (diff) | |
| download | zen-0fe877390805272f8efe6c793ffb83e8c159d50a.tar.xz zen-0fe877390805272f8efe6c793ffb83e8c159d50a.zip | |
Merge branch 'main' into gc
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/include/zencore/iobuffer.h | 3 | ||||
| -rw-r--r-- | zencore/include/zencore/string.h | 4 | ||||
| -rw-r--r-- | zencore/string.cpp | 6 |
3 files changed, 11 insertions, 2 deletions
diff --git a/zencore/include/zencore/iobuffer.h b/zencore/include/zencore/iobuffer.h index db462e238..8679511c9 100644 --- a/zencore/include/zencore/iobuffer.h +++ b/zencore/include/zencore/iobuffer.h @@ -357,6 +357,9 @@ public: [[nodiscard]] inline ZenContentType GetContentType() const { return m_Core->GetContentType(); } [[nodiscard]] ZENCORE_API bool GetFileReference(IoBufferFileReference& OutRef) const; + template<typename T> + [[nodiscard]] const T* Data() const { return reinterpret_cast<const T*>(m_Core->DataPointer()); } + private: RefPtr<IoBufferCore> m_Core = new IoBufferCore; diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h index a94e063a4..630341056 100644 --- a/zencore/include/zencore/string.h +++ b/zencore/include/zencore/string.h @@ -632,7 +632,7 @@ HashStringAsLowerDjb2(const std::string_view& InString) { uint32_t HashValue = 5381; - for (int CurChar : InString) + for (uint8_t CurChar : InString) { CurChar -= ((CurChar - 'A') <= ('Z' - 'A')) * ('A' - 'a'); // this should be compiled into branchless logic HashValue = HashValue * 33 + CurChar; @@ -650,7 +650,7 @@ ToLower(const std::string_view& InString) for (char& CurChar : Out) { - CurChar -= ((CurChar - 'A') <= ('Z' - 'A')) * ('A' - 'a'); // this should be compiled into branchless logic + CurChar -= (uint8_t(CurChar - 'A') <= ('Z' - 'A')) * ('A' - 'a'); // this should be compiled into branchless logic } return Out; diff --git a/zencore/string.cpp b/zencore/string.cpp index 8e7921bb6..43381aa5d 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -936,6 +936,12 @@ TEST_CASE("string") CHECK(HashStringAsLowerDjb2("aBCd"sv) == HashStringDjb2(ToLower("aBCd"sv))); } + SUBCASE("tolower") + { + CHECK_EQ(ToLower("te!st"sv), "te!st"sv); + CHECK_EQ(ToLower("TE%St"sv), "te%st"sv); + } + SUBCASE("ForEachStrTok") { const auto Tokens = "here,is,my,different,tokens"sv; |