[ox] Remove some unnecessary const_casts

This commit is contained in:
2026-01-27 23:01:01 -06:00
parent 46a7331754
commit 7681830ca6
2 changed files with 12 additions and 17 deletions

View File

@@ -175,8 +175,8 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
ox::FileStore32 fileStore(list, buffLen);
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1), "FileStore::write 1 failed.");
oxAssert(fileStore.write(5, const_cast<char*>(str2), str2Len, 1), "FileStore::write 2 failed.");
oxAssert(fileStore.write(4, str1, str1Len, 1), "FileStore::write 1 failed.");
oxAssert(fileStore.write(5, str2, str2Len, 1), "FileStore::write 2 failed.");
char str1Read[str1Len];
size_t str1ReadSize = 0;

View File

@@ -7,9 +7,9 @@
*/
#include "def.hpp"
#include "span.hpp"
#include "strops.hpp"
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
@@ -19,30 +19,25 @@ static_assert(ox::strcmp("resize", "resize") == 0, "resize == resize");
static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");
static_assert([] {
auto testStr = "asdf";
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
return ox::strchr(testStr, 0, 4) == &testStr[4];
OX_CLANG_NOWARN_END
auto constexpr testStr = ox::Span{"asdf"};
return ox::strchr(testStr.data(), 0, 4) == &testStr[4];
}(), "ox::strchr 0");
static_assert([] {
int retval = 0;
auto testStr = "aaaa";
auto constexpr testStr = "aaaa";
// test the const and non-const versions of ox::lastIndexOf
retval |= !(ox::lastIndexOf(const_cast<char*>(testStr), 'a', ox::strlen(testStr)) == 3);
retval |= !(ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3);
return retval == 0;
return ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3;
}(), "ox::lastIndexOf aaaa a");
#ifndef OX_USE_STDLIB
extern "C"
std::size_t strlen(const char *str) {
std::size_t len = 0;
for (; str[len]; len++);
size_t strlen(const char *str) {
size_t len{};
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
while (str[len]) { ++len; }
OX_ALLOW_UNSAFE_BUFFERS_END
return len;
}
#endif
OX_ALLOW_UNSAFE_BUFFERS_END