diff --git a/deps/ox/src/ox/std/assert.hpp b/deps/ox/src/ox/std/assert.hpp index a9fcfff1..4eb766ff 100644 --- a/deps/ox/src/ox/std/assert.hpp +++ b/deps/ox/src/ox/std/assert.hpp @@ -80,7 +80,7 @@ constexpr void expect(const char *file, int line, const auto &actual, const auto if (!std::is_constant_evaluated()) { #if defined(OX_USE_STDLIB) oxErrf("\n\033[31;1;1mASSERT FAILURE:\033[0m [{}:{}]: {}\n", file, line, "Value incorrect"); - oxErrf("expected: {}, actual: {}\n", detail::toStringView(expected), detail::toStringView(actual)); + oxErrf("expected: {}\nactual: {}\n", detail::toStringView(expected), detail::toStringView(actual)); printStackTrace(2); oxTracef("assert::expect", "Failed assert: {} == {} [{}:{}]", detail::toStringView(actual), detail::toStringView(expected), file, line); std::abort(); diff --git a/deps/ox/src/ox/std/test/CMakeLists.txt b/deps/ox/src/ox/std/test/CMakeLists.txt index 05add638..85052f76 100644 --- a/deps/ox/src/ox/std/test/CMakeLists.txt +++ b/deps/ox/src/ox/std/test/CMakeLists.txt @@ -21,3 +21,4 @@ add_test("[ox/std] BufferWriter" StdTest "BufferWriter") add_test("[ox/std] StringSplit" StdTest "StringSplit") add_test("[ox/std] FromHex" StdTest "FromHex") add_test("[ox/std] ToHex" StdTest "ToHex") +add_test("[ox/std] UUID" StdTest "UUID") diff --git a/deps/ox/src/ox/std/test/tests.cpp b/deps/ox/src/ox/std/test/tests.cpp index 9d96c9de..96af15a2 100644 --- a/deps/ox/src/ox/std/test/tests.cpp +++ b/deps/ox/src/ox/std/test/tests.cpp @@ -197,6 +197,16 @@ static std::map tests = { oxExpect(ox::detail::toHex(0x0f), "0f"); oxExpect(ox::detail::toHex(0x93), "93"); oxExpect(ox::detail::toHex(0x40), "40"); + oxExpect(ox::detail::toHex(0xf0), "f0"); + return OxError(0); + } + }, + { + "UUID", + [] { + constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db"; + oxRequire(uuid, ox::UUID::fromString(uuidStr)); + oxExpect(ox::StringView(uuid.toString()), uuidStr); return OxError(0); } }, diff --git a/deps/ox/src/ox/std/uuid.hpp b/deps/ox/src/ox/std/uuid.hpp index 34f42d7b..aa5d711a 100644 --- a/deps/ox/src/ox/std/uuid.hpp +++ b/deps/ox/src/ox/std/uuid.hpp @@ -81,7 +81,7 @@ constexpr ox::BString<2> toHex(uint8_t v) noexcept { 'f', }; ox::Array out; - out[0] = valMap[static_cast((v & 0xf0) / 0xf)]; + out[0] = valMap[static_cast((v & 0xf0) / 16)]; out[1] = valMap[static_cast(v & 0x0f)]; out[2] = 0; return out.data(); @@ -100,10 +100,16 @@ class UUID { static ox::Result generate() noexcept; - constexpr ox::Error fromString(ox::CRStringView s) noexcept { + [[nodiscard]] + constexpr auto value() const noexcept { + return m_value; + } + + static constexpr ox::Result fromString(ox::CRStringView s) noexcept { if (s.len() < 36) { return OxError(1, "Insufficient data contain complete UUID"); } + UUID out; auto valueI = 0u; for (auto i = 0u; i < s.len();) { if (s[i] == '-') { @@ -115,35 +121,39 @@ class UUID { return OxError(1, "Invalid UUID"); } oxRequire(val, detail::fromHex(seg)); - m_value[valueI] = val; + out.m_value[valueI] = val; i += 2; ++valueI; } - return {}; + return out; } [[nodiscard]] constexpr UUIDStr toString() const noexcept { UUIDStr out; - auto i = 0u; + auto valueI = 0u; constexpr auto printChars = []( - ox::BString<36> *out, const Array &value, std::size_t cnt, unsigned i) { - for (; i < cnt; ++i) { - const auto v = value[i]; + ox::BString<36> *out, + const Array &value, + std::size_t cnt, + unsigned valueI) { + for (auto i = 0u; i < cnt; ++i) { + const auto v = value[valueI]; const auto h = detail::toHex(v); oxIgnoreError(out->append(h.c_str(), h.len())); + ++valueI; } - return i; + return valueI; }; - i = printChars(&out, m_value, 4, i); + valueI = printChars(&out, m_value, 4, valueI); out += "-"; - i = printChars(&out, m_value, 2, i); + valueI = printChars(&out, m_value, 2, valueI); out += "-"; - i = printChars(&out, m_value, 2, i); + valueI = printChars(&out, m_value, 2, valueI); out += "-"; - i = printChars(&out, m_value, 2, i); + valueI = printChars(&out, m_value, 2, valueI); out += "-"; - i = printChars(&out, m_value, 6, i); + valueI = printChars(&out, m_value, 6, valueI); return out; } };