From b156ee3141f9609300d7f54368787da79aa0a9fe Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 9 Jun 2023 22:07:19 -0500 Subject: [PATCH] [ox/std] Add UUID::toString variant that takes a Writer_c (synced from bb85e6ab6c834a110b48c19713ea51fa25f622a9) --- src/ox/std/uuid.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ox/std/uuid.hpp b/src/ox/std/uuid.hpp index 6a049e042..031222bef 100644 --- a/src/ox/std/uuid.hpp +++ b/src/ox/std/uuid.hpp @@ -145,6 +145,33 @@ class UUID { return out; } + [[nodiscard]] + constexpr ox::Error toString(Writer_c auto &writer) const noexcept { + auto valueI = 0u; + constexpr auto printChars = []( + Writer_c auto &writer, + 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(writer.write(h.c_str(), h.len())); + ++valueI; + } + }; + printChars(writer, m_value, 4, valueI); + oxReturnError(writer.put('-')); + printChars(writer, m_value, 2, valueI); + oxReturnError(writer.put('-')); + printChars(writer, m_value, 2, valueI); + oxReturnError(writer.put('-')); + printChars(writer, m_value, 2, valueI); + oxReturnError(writer.put('-')); + printChars(writer, m_value, 6, valueI); + return {}; + } + [[nodiscard]] constexpr UUIDStr toString() const noexcept { UUIDStr out;