Compare commits

...

5 Commits

Author SHA1 Message Date
gary 59dbfe0db1 [studio] Cleanup
Build / build (push) Successful in 1m11s
2026-05-17 15:05:44 -05:00
gary 2c50ce48ed [ox/std] Add Result::reoriginate functions 2026-05-17 15:02:07 -05:00
gary 72e16cb285 [studio] Change output of Claw OC files to make them recognizable as test files 2026-05-17 14:53:42 -05:00
gary d1e410ac55 [ox/std] Add caseInsensitiveEquals 2026-05-17 14:30:43 -05:00
gary be32d575f5 [ox/claw] Add writeClaw Writer_c variant 2026-05-17 14:29:43 -05:00
6 changed files with 74 additions and 9 deletions
+21
View File
@@ -120,4 +120,25 @@ Result<Buffer> writeClaw(
return out;
}
Error writeClaw(
auto const &obj,
Writer_c auto &writer,
ClawFormat const fmt = ClawFormat::Metal) noexcept {
OX_RETURN_ERROR(detail::writeClawHeader(writer, &obj, fmt));
#ifdef OX_USE_STDLIB
if (fmt == ClawFormat::Metal) {
OX_RETURN_ERROR(writeMC(writer, obj));
} else if (fmt == ClawFormat::Organic) {
OX_REQUIRE(data, writeOC(obj));
OX_RETURN_ERROR(writer.write(data.data(), data.size()));
}
#else
if (fmt != ClawFormat::Metal) {
return ox::Error(1, "OC is not supported in this build");
}
OX_RETURN_ERROR(writeMC(writer, obj));
#endif
return {};
}
}
+15
View File
@@ -345,6 +345,21 @@ struct [[nodiscard]] Result {
return *this;
}
constexpr Result reoriginate(
ErrorCode const pErrCode,
CString const pMsg = nullptr,
std::source_location const &pSrc = std::source_location::current()) const && noexcept {
if (error) {
return {std::move(value), Error{pErrCode, pMsg, pSrc}};
}
return Error{};
}
constexpr Result reoriginate(
std::source_location const &pSrc = std::source_location::current()) const && noexcept {
return {std::move(value), Error{error.errCode, error.msg, pSrc}};
}
};
namespace detail {
+21
View File
@@ -36,6 +36,27 @@ constexpr StringView substr(StringViewCR str, std::size_t const start, std::size
return {};
}
[[nodiscard]]
constexpr char toUpper(char const c) noexcept {
return c & 0b1101'1111;
}
[[nodiscard]]
constexpr int caseInsensitiveEquals(ox::StringViewCR a, ox::StringViewCR b) noexcept {
auto const sz = ox::min(a.size(), b.size());
for (size_t i{}; i < sz; ++i) {
auto const ac = toUpper(a[i]);
auto const bc = toUpper(b[i]);
if (ac < bc) {
return -1;
}
if (ac > bc) {
return 1;
}
}
return 0;
}
[[nodiscard]]
constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept {
return base.size() && base[0] == beginning;
@@ -4,6 +4,8 @@
#include <imgui.h>
#include <studio/context.hpp>
#include "clawviewer.hpp"
namespace studio {
@@ -16,11 +16,17 @@ static ox::Error convertFile(
ox::TypeStore &ts,
ox::StringViewCR path,
ox::ClawFormat const fmt) noexcept {
ox::Buffer buff;
ox::ModelObject obj;
OX_RETURN_ERROR(fs.read(path).moveTo(buff).reoriginate(1, "unable to read file"));
OX_RETURN_ERROR(keel::readAsset(ts, buff).moveTo(obj).reoriginate(1, "unable to parse file"));
OX_RETURN_ERROR(ox::writeClaw(obj, fmt).moveTo(buff));
OX_REQUIRE_M(buff, fs.read(path).reoriginate(1, "unable to read file"));
OX_REQUIRE(uuid, keel::readUuidHeader(buff));
OX_REQUIRE(obj, keel::readAsset(ts, buff).reoriginate(1, "unable to parse file"));
buff.clear();
ox::BufferWriter wrtr{&buff};
OX_RETURN_ERROR(keel::writeUuidHeader(wrtr, uuid));
OX_RETURN_ERROR(ox::writeClaw(obj, wrtr, fmt));
if (fmt == ox::ClawFormat::Organic) {
*buff.back().value = '\n';
}
OX_RETURN_ERROR(wrtr.write(buff.data(), buff.size()));
OX_RETURN_ERROR(fs.write(path, buff).reoriginate(1, "unable to write file"));
return {};
}
@@ -31,12 +37,12 @@ static void printUsage() noexcept {
[[nodiscard]]
static constexpr ox::Result<ox::ClawFormat> getFmt(ox::StringViewCR fmtStr) noexcept {
if (fmtStr == "mc") {
if (caseInsensitiveEquals(fmtStr, "mc") == 0) {
return ox::ClawFormat::Metal;
} else if (fmtStr == "oc") {
} else if (caseInsensitiveEquals(fmtStr, "oc") == 0) {
return ox::ClawFormat::Organic;
}
return ox::Error(1, "invalid format");
return ox::Error{1, "invalid format"};
}
ox::Error cmdChangeFormat(Project &project, ox::SpanView<ox::CString> const args) noexcept {
@@ -165,7 +165,7 @@ template<typename T>
ox::Error Project::writeObj(ox::StringViewCR path, T const &obj, ox::ClawFormat fmt) noexcept {
OX_REQUIRE_M(buff, ox::writeClaw(obj, fmt));
if (fmt == ox::ClawFormat::Organic) {
buff.pop_back();
*buff.back().value = '\n';
}
// write to FS
OX_RETURN_ERROR(mkdir(parentDir(path)));