[ox/std] Add UUID::toString variant that takes a Writer_c
This commit is contained in:
parent
fb43c956e7
commit
bb85e6ab6c
27
deps/ox/src/ox/std/uuid.hpp
vendored
27
deps/ox/src/ox/std/uuid.hpp
vendored
@ -145,6 +145,33 @@ class UUID {
|
|||||||
return out;
|
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<uint8_t, 16> &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]]
|
[[nodiscard]]
|
||||||
constexpr UUIDStr toString() const noexcept {
|
constexpr UUIDStr toString() const noexcept {
|
||||||
UUIDStr out;
|
UUIDStr out;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user