From 0885919dbddf75b4c0e7a568262cfd53d4d94245 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 29 Apr 2026 01:43:41 -0500 Subject: [PATCH] [ox/std] Cleanup --- deps/ox/src/ox/std/error.hpp | 14 ++++++--- deps/ox/src/ox/std/fmt.hpp | 60 ++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index a9eff7eb..98a4fd05 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -62,13 +62,19 @@ struct [[nodiscard]] Error { return errCode; } - constexpr void throwException() const; + /** + * Checks the Error to see if is not OK, and throws the Error as an ox::Exception if not. + */ + constexpr void checkThrow() const; constexpr Error reoriginate( ErrorCode const pErrCode, CString const pMsg = nullptr, std::source_location const &pSrc = std::source_location::current()) const noexcept { - return Error{pErrCode, pMsg, pSrc}; + if (errCode) { + return Error{pErrCode, pMsg, pSrc}; + } + return Error{}; } constexpr Error reoriginate( @@ -102,7 +108,7 @@ struct Exception: public std::exception { explicit Exception( ErrorCode const errCode, - CString msg, + CString const msg, std::source_location const &src = std::source_location::current()) noexcept: src{src}, msg{msg}, @@ -124,7 +130,7 @@ struct Exception: public std::exception { }; -constexpr void Error::throwException() const { +constexpr void Error::checkThrow() const { if (errCode) [[unlikely]] { throw Exception{*this}; } diff --git a/deps/ox/src/ox/std/fmt.hpp b/deps/ox/src/ox/std/fmt.hpp index 1cde475d..41d7077d 100644 --- a/deps/ox/src/ox/std/fmt.hpp +++ b/deps/ox/src/ox/std/fmt.hpp @@ -31,27 +31,27 @@ namespace ox { namespace detail { template -constexpr StringView toStringView(const StringView &s) noexcept { +constexpr StringView toStringView(StringViewCR s) noexcept { return s; } template -constexpr StringView toStringView(const char *s) noexcept { +constexpr StringView toStringView(CString const s) noexcept { return s; } template -constexpr StringView toStringView(const IString &s) noexcept { +constexpr StringView toStringView(IString const &s) noexcept { return s; } template -constexpr StringView toStringView(ox::StringLiteral s) noexcept { +constexpr StringView toStringView(StringLiteral const &s) noexcept { return s; } template -constexpr StringView toStringView(const BasicString &s) noexcept { +constexpr StringView toStringView(BasicString const &s) noexcept { return s; } @@ -62,20 +62,20 @@ constexpr #else inline #endif -StringView toStringView(const std::string &s) noexcept { +StringView toStringView(std::string const &s) noexcept { return s.c_str(); } #endif #if __has_include() template -inline StringView toStringView(const QString &s) noexcept { +inline StringView toStringView(QString const &s) noexcept { return s.toUtf8().data(); } #endif template -constexpr StringView toStringView(const auto&) noexcept requires(force) { +constexpr StringView toStringView(auto const&) noexcept requires(force) { return ""; } @@ -83,10 +83,10 @@ class FmtArg { private: static constexpr auto DataSz = 23; - ox::Array dataStr{}; + Array dataStr{}; template - constexpr StringView sv(const T &v, ox::Span dataStr) noexcept { + constexpr StringView sv(T const &v, Span dataStr) noexcept { if constexpr(is_bool_v) { return v ? "true" : "false"; } else if constexpr(is_integer_v) { @@ -99,25 +99,25 @@ class FmtArg { } public: - const StringView out = nullptr; + StringView const out; template - constexpr FmtArg(const T &v) noexcept: out(sv(v, dataStr)) { + constexpr FmtArg(T const &v) noexcept: out(sv(v, dataStr)) { } }; [[nodiscard]] -constexpr uint64_t argCount(StringView str) noexcept { +constexpr uint64_t argCount(StringViewCR str) noexcept { uint64_t cnt = 0; - const auto prev = [str](std::size_t i) -> char { + auto const prev = [str](std::size_t i) -> char { if (i > 0) { return str[i - 1]; } else { return '\0'; } }; - const auto next = [str](std::size_t i) -> char { + auto const next = [str](std::size_t i) -> char { if (i < str.bytes() - 1) { return str[i + 1]; } else { @@ -133,14 +133,14 @@ constexpr uint64_t argCount(StringView str) noexcept { } struct FmtSegment { - const char *str = nullptr; - unsigned length = 0; + CString str{}; + unsigned length{}; - constexpr bool operator==(const FmtSegment &o) const noexcept { + constexpr bool operator==(FmtSegment const &o) const noexcept { return length == o.length && ox::strncmp(str, o.str, length) == 0; } - constexpr bool operator!=(const FmtSegment &o) const noexcept { + constexpr bool operator!=(FmtSegment const &o) const noexcept { return length != o.length || ox::strncmp(str, o.str, length) != 0; } }; @@ -148,9 +148,9 @@ struct FmtSegment { template struct Fmt { static constexpr std::size_t size = sz; - ox::Array segments; + Array segments; - constexpr bool operator==(const Fmt &o) const noexcept { + constexpr bool operator==(Fmt const &o) const noexcept { for (std::size_t i = 0; i < sz; ++i) { if (segments[i] != o.segments[i]) { return false; @@ -162,16 +162,16 @@ struct Fmt { template [[nodiscard]] -constexpr Fmt fmtSegments(StringView fmt) noexcept { +constexpr Fmt fmtSegments(StringViewCR fmt) noexcept { Fmt out; - const auto prev = [fmt](std::size_t i) -> char { + auto const prev = [fmt](std::size_t const i) -> char { if (i > 0) { return fmt[i - 1]; } else { return '\0'; } }; - const auto next = [fmt](std::size_t i) -> char { + auto const next = [fmt](std::size_t const i) -> char { if (i < fmt.bytes() - 1) { return fmt[i + 1]; } else { @@ -197,23 +197,23 @@ constexpr Fmt fmtSegments(StringView fmt) noexcept { template [[nodiscard]] -constexpr StringType sfmt(StringView fmt, Args&&... args) noexcept { +constexpr StringType sfmt(StringViewCR fmt, Args&&... args) noexcept { assert(ox::detail::argCount(fmt) == sizeof...(args)); StringType out; - const auto fmtSegments = ox::detail::fmtSegments(fmt); - const auto &firstSegment = fmtSegments.segments[0]; + auto const fmtSegments = detail::fmtSegments(fmt); + auto const &firstSegment = fmtSegments.segments[0]; std::ignore = out.append(firstSegment.str, firstSegment.length); - const detail::FmtArg elements[sizeof...(args)] = {args...}; + detail::FmtArg const elements[sizeof...(args)] = {args...}; for (size_t i = 0; i < fmtSegments.size - 1; ++i) { std::ignore = out.append(elements[i].out); - const auto &s = fmtSegments.segments[i + 1]; + auto const &s = fmtSegments.segments[i + 1]; std::ignore = out.append(s.str, s.length); } return out; } template -constexpr Result join(auto const&d, auto const&list) { +constexpr Result join(auto const &d, auto const &list) { if (!list.size()) { return T(""); }