[ox/std] Fix code duplication

This commit is contained in:
Gary Talent 2023-06-10 01:15:55 -05:00
parent bb85e6ab6c
commit 20e5b7e617

View File

@ -175,28 +175,9 @@ class UUID {
[[nodiscard]]
constexpr UUIDStr toString() const noexcept {
UUIDStr out;
auto valueI = 0u;
constexpr auto printChars = [](
UUIDStr *out,
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(out->append(h.c_str(), h.len()));
++valueI;
}
};
printChars(&out, m_value, 4, valueI);
out += "-";
printChars(&out, m_value, 2, valueI);
out += "-";
printChars(&out, m_value, 2, valueI);
out += "-";
printChars(&out, m_value, 2, valueI);
out += "-";
printChars(&out, m_value, 6, valueI);
ox::CharBuffWriter bw(out.data(), out.cap());
oxIgnoreError(toString(bw));
out[out.cap()] = 0;
return out;
}
};