Compare commits

..

No commits in common. "95a69b72b535ea4b619a8a0504a94333dd276da1" and "2761f23d31a4c2eb8ad4e5de5dc84d65b85f170f" have entirely different histories.

3 changed files with 34 additions and 19 deletions

View File

@ -13,7 +13,6 @@ namespace ox {
template class BasicString<8>; template class BasicString<8>;
static_assert(StringView("Write") != String("")); static_assert(StringView("Write") != String(""));
static_assert(ox::strcmp(String{}.c_str(), "\0") == 0);
static_assert(String("Write") != StringView("")); static_assert(String("Write") != StringView(""));
static_assert(String("Write") == StringView("Write")); static_assert(String("Write") == StringView("Write"));
static_assert(String(StringView("Write")) == StringView("Write")); static_assert(String(StringView("Write")) == StringView("Write"));

View File

@ -193,7 +193,6 @@ class BasicString {
constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept; constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept;
constexpr void resize(size_t sz) noexcept { constexpr void resize(size_t sz) noexcept {
++sz;
m_buff.resize(sz); m_buff.resize(sz);
m_buff[sz - 1] = 0; m_buff[sz - 1] = 0;
} }
@ -250,19 +249,38 @@ class BasicString {
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString() noexcept { constexpr BasicString<SmallStringSize_v>::BasicString() noexcept {
m_buff.resize(1); if (!m_buff.empty()) {
m_buff[0] = 0;
} else {
m_buff.push_back(0);
}
} }
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {} constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {
// GCC complains if you don't do this pretty unnecessary size check
if (!m_buff.empty()) {
m_buff[0] = 0;
}
}
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept { constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept {
if (!m_buff.empty()) {
m_buff[0] = 0;
} else {
m_buff.push_back(0);
}
set(str); set(str);
} }
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char8_t *str) noexcept { constexpr BasicString<SmallStringSize_v>::BasicString(const char8_t *str) noexcept {
if (!m_buff.empty()) {
m_buff[0] = 0;
} else {
m_buff.push_back(0);
}
set(str); set(str);
} }
@ -270,15 +288,21 @@ template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str, std::size_t size) noexcept { constexpr BasicString<SmallStringSize_v>::BasicString(const char *str, std::size_t size) noexcept {
m_buff.resize(size + 1); m_buff.resize(size + 1);
ox::listcpy(m_buff.data(), str, size); ox::listcpy(m_buff.data(), str, size);
m_buff[size] = 0;
} }
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept: constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept:
BasicString(StringView{str.data(), str.len()}) { BasicString(StringView{str.data(), str.bytes()}) {
} }
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept { constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept {
if (m_buff.empty()) {
m_buff.push_back(0);
} else {
m_buff[0] = 0;
}
set(str); set(str);
} }
@ -289,8 +313,6 @@ constexpr BasicString<SmallStringSize_v>::BasicString(const BasicString &other)
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(BasicString &&other) noexcept: m_buff(std::move(other.m_buff)) { constexpr BasicString<SmallStringSize_v>::BasicString(BasicString &&other) noexcept: m_buff(std::move(other.m_buff)) {
other.m_buff.resize(1);
other.m_buff[0] = 0;
} }
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
@ -336,8 +358,6 @@ template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(BasicString &&src) noexcept { constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(BasicString &&src) noexcept {
if (this != &src) { if (this != &src) {
m_buff = std::move(src.m_buff); m_buff = std::move(src.m_buff);
src.m_buff.resize(1);
src.m_buff[0] = 0;
} }
return *this; return *this;
} }

View File

@ -134,20 +134,16 @@ void setPixel(TileSheet::SubSheet &ss, int8_t pBpp, ox::Point const&pt, uint8_t
} }
static ox::Error setPixelCount(ox::Vector<uint8_t> &pixels, int8_t pBpp, std::size_t cnt) noexcept { static ox::Error setPixelCount(ox::Vector<uint8_t> &pixels, int8_t pBpp, std::size_t cnt) noexcept {
size_t sz{};
switch (pBpp) { switch (pBpp) {
case 4: case 4:
sz = cnt / 2; pixels.resize(cnt / 2);
break; return OxError(0);
case 8: case 8:
sz = cnt; pixels.resize(cnt);
break; return OxError(0);
default: default:
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount"); return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
} }
pixels.reserve(sz);
pixels.resize(sz);
return {};
} }
ox::Error setPixelCount(TileSheet::SubSheet &ss, int8_t pBpp, std::size_t cnt) noexcept { ox::Error setPixelCount(TileSheet::SubSheet &ss, int8_t pBpp, std::size_t cnt) noexcept {
@ -162,8 +158,8 @@ unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept {
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept { ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept {
ox::Vector<uint8_t> out; ox::Vector<uint8_t> out;
oxReturnError(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile)); oxReturnError(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
auto const w = ss.columns * TileWidth; auto const w = sz.width * TileWidth;
auto const h = ss.rows * TileHeight; auto const h = sz.height * TileHeight;
for (auto x = 0; x < w; ++x) { for (auto x = 0; x < w; ++x) {
for (auto y = 0; y < h; ++y) { for (auto y = 0; y < h; ++y) {
auto const palIdx = getPixel(ss, pBpp, {x, y}); auto const palIdx = getPixel(ss, pBpp, {x, y});