Compare commits
No commits in common. "18bb50626d38c1dca2e01e3a8127eb36f5c23e97" and "e30ebce4c046ea2d610ae867cb6feaea5740f891" have entirely different histories.
18bb50626d
...
e30ebce4c0
4
deps/ox/src/ox/std/fmt.hpp
vendored
4
deps/ox/src/ox/std/fmt.hpp
vendored
@ -195,9 +195,9 @@ constexpr StringType sfmt(StringView fmt, Args&&... args) noexcept {
|
|||||||
std::ignore = out.append(firstSegment.str, firstSegment.length);
|
std::ignore = out.append(firstSegment.str, firstSegment.length);
|
||||||
const detail::FmtArg elements[sizeof...(args)] = {args...};
|
const detail::FmtArg elements[sizeof...(args)] = {args...};
|
||||||
for (size_t i = 0; i < fmtSegments.size - 1; ++i) {
|
for (size_t i = 0; i < fmtSegments.size - 1; ++i) {
|
||||||
std::ignore = out.append(elements[i].out);
|
out += elements[i].out;
|
||||||
const auto &s = fmtSegments.segments[i + 1];
|
const auto &s = fmtSegments.segments[i + 1];
|
||||||
std::ignore = out.append(s.str);
|
std::ignore = out.append(s.str, s.length);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
102
deps/ox/src/ox/std/istring.hpp
vendored
102
deps/ox/src/ox/std/istring.hpp
vendored
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "array.hpp"
|
#include "ignore.hpp"
|
||||||
#include "memops.hpp"
|
#include "memops.hpp"
|
||||||
#include "ox/std/error.hpp"
|
#include "ox/std/error.hpp"
|
||||||
#include "stringview.hpp"
|
#include "stringview.hpp"
|
||||||
@ -20,7 +20,7 @@ namespace ox {
|
|||||||
template<std::size_t StrCap>
|
template<std::size_t StrCap>
|
||||||
class IString {
|
class IString {
|
||||||
private:
|
private:
|
||||||
ox::Array<char, StrCap + 1> m_buff;
|
char m_buff[StrCap + 1];
|
||||||
size_t m_size{};
|
size_t m_size{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -38,6 +38,19 @@ class IString {
|
|||||||
|
|
||||||
constexpr IString &operator=(Integer_c auto i) noexcept;
|
constexpr IString &operator=(Integer_c auto i) noexcept;
|
||||||
|
|
||||||
|
constexpr IString &operator+=(const char *str) noexcept;
|
||||||
|
|
||||||
|
constexpr IString &operator+=(char *str) noexcept;
|
||||||
|
|
||||||
|
constexpr IString &operator+=(Integer_c auto i) noexcept;
|
||||||
|
|
||||||
|
constexpr IString &operator+=(StringView s) noexcept;
|
||||||
|
|
||||||
|
constexpr IString operator+(const char *str) const noexcept;
|
||||||
|
|
||||||
|
constexpr IString operator+(char *str) const noexcept;
|
||||||
|
|
||||||
|
constexpr IString operator+(Integer_c auto i) const noexcept;
|
||||||
|
|
||||||
constexpr bool operator==(const char *other) const noexcept;
|
constexpr bool operator==(const char *other) const noexcept;
|
||||||
|
|
||||||
@ -53,8 +66,6 @@ class IString {
|
|||||||
|
|
||||||
constexpr Error append(const char *str, std::size_t strLen) noexcept;
|
constexpr Error append(const char *str, std::size_t strLen) noexcept;
|
||||||
|
|
||||||
constexpr Error append(ox::StringView str) noexcept;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const char *data() const noexcept;
|
constexpr const char *data() const noexcept;
|
||||||
|
|
||||||
@ -101,9 +112,9 @@ constexpr IString<size>::IString(const char *str) noexcept: m_buff{{0}} {
|
|||||||
|
|
||||||
template<std::size_t size>
|
template<std::size_t size>
|
||||||
constexpr IString<size> &IString<size>::operator=(Integer_c auto i) noexcept {
|
constexpr IString<size> &IString<size>::operator=(Integer_c auto i) noexcept {
|
||||||
ox::Array<char, 65> str{};
|
char str[65] = {};
|
||||||
ox::itoa(i, str.data());
|
ox::itoa(i, str);
|
||||||
return this->operator=(str.data());
|
return this->operator=(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t size>
|
template<std::size_t size>
|
||||||
@ -113,7 +124,7 @@ constexpr IString<size> &IString<size>::operator=(ox::CRStringView str) noexcept
|
|||||||
strLen = cap();
|
strLen = cap();
|
||||||
}
|
}
|
||||||
m_size = strLen;
|
m_size = strLen;
|
||||||
ox::listcpy(m_buff.data(), str.data(), strLen);
|
ox::listcpy(m_buff, str.data(), strLen);
|
||||||
// make sure last element is a null terminator
|
// make sure last element is a null terminator
|
||||||
m_buff[strLen] = 0;
|
m_buff[strLen] = 0;
|
||||||
return *this;
|
return *this;
|
||||||
@ -126,7 +137,7 @@ constexpr IString<size> &IString<size>::operator=(const char *str) noexcept {
|
|||||||
strLen = cap();
|
strLen = cap();
|
||||||
}
|
}
|
||||||
m_size = strLen;
|
m_size = strLen;
|
||||||
ox::listcpy(m_buff.data(), str, strLen);
|
ox::listcpy(m_buff, str, strLen);
|
||||||
// make sure last element is a null terminator
|
// make sure last element is a null terminator
|
||||||
m_buff[cap()] = 0;
|
m_buff[cap()] = 0;
|
||||||
return *this;
|
return *this;
|
||||||
@ -137,6 +148,52 @@ constexpr IString<size> &IString<size>::operator=(char *str) noexcept {
|
|||||||
return *this = static_cast<const char*>(str);
|
return *this = static_cast<const char*>(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> &IString<size>::operator+=(const char *str) noexcept {
|
||||||
|
std::size_t strLen = ox::strlen(str) + 1;
|
||||||
|
std::ignore = append(str, strLen);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> &IString<size>::operator+=(char *str) noexcept {
|
||||||
|
return *this += static_cast<const char*>(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> &IString<size>::operator+=(Integer_c auto i) noexcept {
|
||||||
|
char str[65] = {};
|
||||||
|
ox::itoa(i, str);
|
||||||
|
return this->operator+=(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> &IString<size>::operator+=(StringView s) noexcept {
|
||||||
|
std::size_t strLen = s.bytes();
|
||||||
|
std::ignore = append(s.data(), strLen);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> IString<size>::operator+(const char *str) const noexcept {
|
||||||
|
auto out = *this;
|
||||||
|
std::size_t strLen = ox::strlen(str) + 1;
|
||||||
|
std::ignore = out.append(str, strLen);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> IString<size>::operator+(char *str) const noexcept {
|
||||||
|
return *this + static_cast<const char*>(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr IString<size> IString<size>::operator+(Integer_c auto i) const noexcept {
|
||||||
|
char str[65] = {};
|
||||||
|
ox::itoa(i, str);
|
||||||
|
return this->operator+(str);
|
||||||
|
}
|
||||||
|
|
||||||
template<std::size_t StrCap>
|
template<std::size_t StrCap>
|
||||||
constexpr bool IString<StrCap>::operator==(const char *other) const noexcept {
|
constexpr bool IString<StrCap>::operator==(const char *other) const noexcept {
|
||||||
return ox::StringView(*this) == other;
|
return ox::StringView(*this) == other;
|
||||||
@ -169,28 +226,13 @@ constexpr char &IString<StrCap>::operator[](std::size_t i) noexcept {
|
|||||||
|
|
||||||
template<std::size_t StrCap>
|
template<std::size_t StrCap>
|
||||||
constexpr Error IString<StrCap>::append(const char *str, std::size_t strLen) noexcept {
|
constexpr Error IString<StrCap>::append(const char *str, std::size_t strLen) noexcept {
|
||||||
Error err{};
|
Error err;
|
||||||
auto currentLen = len();
|
auto currentLen = len();
|
||||||
if (cap() < currentLen + strLen + 1) {
|
if (cap() < currentLen + strLen + 1) {
|
||||||
strLen = cap() - currentLen;
|
strLen = cap() - currentLen;
|
||||||
err = OxError(1, "Insufficient space for full string");
|
err = OxError(1, "Insufficient space for full string");
|
||||||
}
|
}
|
||||||
ox::strncpy(m_buff.data() + currentLen, str, strLen);
|
ox::strncpy(m_buff + currentLen, str, strLen);
|
||||||
// make sure last element is a null terminator
|
|
||||||
m_buff[currentLen + strLen] = 0;
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t StrCap>
|
|
||||||
constexpr Error IString<StrCap>::append(ox::StringView str) noexcept {
|
|
||||||
auto strLen = str.len();
|
|
||||||
Error err{};
|
|
||||||
auto currentLen = len();
|
|
||||||
if (cap() < currentLen + strLen + 1) {
|
|
||||||
strLen = cap() - currentLen;
|
|
||||||
err = OxError(1, "Insufficient space for full string");
|
|
||||||
}
|
|
||||||
ox::strncpy(m_buff.data() + currentLen, str, strLen);
|
|
||||||
// make sure last element is a null terminator
|
// make sure last element is a null terminator
|
||||||
m_buff[currentLen + strLen] = 0;
|
m_buff[currentLen + strLen] = 0;
|
||||||
return err;
|
return err;
|
||||||
@ -198,17 +240,17 @@ constexpr Error IString<StrCap>::append(ox::StringView str) noexcept {
|
|||||||
|
|
||||||
template<std::size_t StrCap>
|
template<std::size_t StrCap>
|
||||||
constexpr const char *IString<StrCap>::data() const noexcept {
|
constexpr const char *IString<StrCap>::data() const noexcept {
|
||||||
return static_cast<const char*>(m_buff.data());
|
return static_cast<const char*>(m_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t StrCap>
|
template<std::size_t StrCap>
|
||||||
constexpr char *IString<StrCap>::data() noexcept {
|
constexpr char *IString<StrCap>::data() noexcept {
|
||||||
return static_cast<char*>(m_buff.data());
|
return static_cast<char*>(m_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t StrCap>
|
template<std::size_t StrCap>
|
||||||
constexpr const char *IString<StrCap>::c_str() const noexcept {
|
constexpr const char *IString<StrCap>::c_str() const noexcept {
|
||||||
return static_cast<const char*>(m_buff.data());
|
return static_cast<const char*>(m_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +258,7 @@ template<std::size_t StrCap>
|
|||||||
constexpr std::size_t IString<StrCap>::len() const noexcept {
|
constexpr std::size_t IString<StrCap>::len() const noexcept {
|
||||||
std::size_t length = 0;
|
std::size_t length = 0;
|
||||||
for (std::size_t i = 0; i < StrCap; i++) {
|
for (std::size_t i = 0; i < StrCap; i++) {
|
||||||
auto const b = static_cast<uint8_t>(m_buff[i]);
|
uint8_t b = static_cast<uint8_t>(m_buff[i]);
|
||||||
if (b) {
|
if (b) {
|
||||||
const auto asciiChar = (b & 128) == 0;
|
const auto asciiChar = (b & 128) == 0;
|
||||||
const auto utf8Char = (b & (256 << 6)) == (256 << 6);
|
const auto utf8Char = (b & (256 << 6)) == (256 << 6);
|
||||||
|
4
deps/ox/src/ox/std/string.hpp
vendored
4
deps/ox/src/ox/std/string.hpp
vendored
@ -178,10 +178,6 @@ class BasicString {
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error append(ox::StringView sv) noexcept {
|
|
||||||
return append(sv.data(), sv.len());
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr BasicString substr(std::size_t pos) const noexcept;
|
constexpr BasicString substr(std::size_t pos) const noexcept;
|
||||||
|
|
||||||
|
9
deps/ox/src/ox/std/test/tests.cpp
vendored
9
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -6,7 +6,6 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ox/std/def.hpp"
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -70,10 +69,10 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
"BString",
|
"BString",
|
||||||
[]() {
|
[]() {
|
||||||
ox::IString<5> s;
|
ox::IString<5> s;
|
||||||
oxReturnError(s.append("A"));
|
s += "A";
|
||||||
oxReturnError(s.append("B"));
|
s += "B";
|
||||||
oxReturnError(s.append("9"));
|
s += 9;
|
||||||
oxReturnError(s.append("C"));
|
s += "C";
|
||||||
oxAssert(s == "AB9C", "BString append broken");
|
oxAssert(s == "AB9C", "BString append broken");
|
||||||
s = "asdf";
|
s = "asdf";
|
||||||
oxAssert(s == "asdf", "String assign broken");
|
oxAssert(s == "asdf", "String assign broken");
|
||||||
|
1
deps/ox/src/ox/std/uuid.hpp
vendored
1
deps/ox/src/ox/std/uuid.hpp
vendored
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ignore.hpp"
|
|
||||||
#include "istring.hpp"
|
#include "istring.hpp"
|
||||||
#include "buffer.hpp"
|
#include "buffer.hpp"
|
||||||
#include "random.hpp"
|
#include "random.hpp"
|
||||||
|
@ -32,7 +32,8 @@ void panic(const char *file, int line, const char *panicMsg, ox::Error const&err
|
|||||||
std::ignore = initConsole(*ctx);
|
std::ignore = initConsole(*ctx);
|
||||||
setBgStatus(*ctx, 0, true);
|
setBgStatus(*ctx, 0, true);
|
||||||
clearBg(*ctx, 0);
|
clearBg(*ctx, 0);
|
||||||
auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err));
|
ox::IString<23> serr = "Error code: ";
|
||||||
|
serr += static_cast<int64_t>(err);
|
||||||
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
||||||
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||||
puts(*ctx, 32 + 2, 6, panicMsg);
|
puts(*ctx, 32 + 2, 6, panicMsg);
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include <ox/std/point.hpp>
|
#include <ox/std/point.hpp>
|
||||||
#include <keel/media.hpp>
|
#include <keel/media.hpp>
|
||||||
|
|
||||||
#include "ox/std/buffer.hpp"
|
|
||||||
#include "ox/std/cstrops.hpp"
|
|
||||||
#include "tilesheeteditor-imgui.hpp"
|
#include "tilesheeteditor-imgui.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
@ -442,9 +440,7 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
|
|||||||
ImGui::PushID(static_cast<int>(i));
|
ImGui::PushID(static_cast<int>(i));
|
||||||
// Column: color idx
|
// Column: color idx
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ox::IString<8> label;
|
auto const label = ox::IString<8>() + (i + 1);
|
||||||
ox::CharBuffWriter w(label.data(), label.bytes());
|
|
||||||
std::ignore = ox::writeItoa(i + 1, w);
|
|
||||||
auto const rowSelected = i == m_view.palIdx();
|
auto const rowSelected = i == m_view.palIdx();
|
||||||
if (ImGui::Selectable(label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
if (ImGui::Selectable(label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||||
m_view.setPalIdx(i);
|
m_view.setPalIdx(i);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user