[nostalgia] Replace C strings with ox::StringView

This commit is contained in:
2022-12-31 17:14:43 -06:00
parent 55ea405a54
commit 679226ef73
31 changed files with 81 additions and 75 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
return OxError(1);
}
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
auto ctx = ox::make_unique<Context>();
ctx->rom = std::move(fs);
ctx->appName = appName;
+5 -4
View File
@@ -85,7 +85,7 @@ ox::Error shutdownGfx(Context*) noexcept {
return {};
}
void setWindowTitle(Context*, const char*) noexcept {
void setWindowTitle(Context*, ox::CRStringView) noexcept {
}
void focusWindow(Context*) noexcept {
@@ -210,10 +210,11 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &p
}
// Do NOT use Context in the GBA version of this function.
void puts(Context *ctx, int column, int row, const char *str) noexcept {
for (int i = 0; str[i]; i++) {
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
const auto col = static_cast<unsigned>(column);
for (auto i = 0u; i < str.bytes(); i++) {
const auto c = charMap[static_cast<unsigned>(str[i])];
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(c));
setTile(ctx, 0, static_cast<int>(col + i), row, static_cast<uint8_t>(c));
}
}
+1 -1
View File
@@ -11,7 +11,7 @@
namespace nostalgia::core {
ox::Result<char*> loadRom(const char*) noexcept {
ox::Result<char*> loadRom(ox::CRStringView) noexcept {
// put the header in the wrong order to prevent mistaking this code for the
// media section
constexpr auto headerP2 = "HEADER__________";
+1 -1
View File
@@ -27,7 +27,7 @@ void panic(const char*, int, const char *msg, const ox::Error &err) noexcept {
puts(nullptr, 32 + 1, 4, "UNEXPECTED STATE:");
puts(nullptr, 32 + 2, 6, msg);
if (err) {
puts(nullptr, 32 + 2, 8, serr.c_str());
puts(nullptr, 32 + 2, 8, serr);
}
puts(nullptr, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
// disable all interrupt handling and IntrWait on no interrupts