[ox] Rename BString to IString

This commit is contained in:
Gary Talent 2024-04-24 00:54:02 -05:00
parent ed4f0e1f2b
commit a00a0bd2ff
25 changed files with 103 additions and 101 deletions

View File

@ -29,7 +29,7 @@ struct TestStructNest {
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
bool Bool = false; bool Bool = false;
uint32_t Int = 0; uint32_t Int = 0;
ox::BString<32> String = ""; ox::IString<32> String = "";
}; };
struct TestStruct { struct TestStruct {
@ -47,7 +47,7 @@ struct TestStruct {
int32_t Int8 = 0; int32_t Int8 = 0;
int unionIdx = 1; int unionIdx = 1;
TestUnion Union; TestUnion Union;
ox::BString<32> String = ""; ox::IString<32> String = "";
uint32_t List[4] = {0, 0, 0, 0}; uint32_t List[4] = {0, 0, 0, 0};
TestStructNest EmptyStruct; TestStructNest EmptyStruct;
TestStructNest Struct; TestStructNest Struct;

View File

@ -132,14 +132,14 @@ Error PathIterator::next(char *pathOut, std::size_t pathOutSize) {
/** /**
* @return 0 if no error * @return 0 if no error
*/ */
Error PathIterator::get(BString<MaxFileNameLength> *fileName) { Error PathIterator::get(IString<MaxFileNameLength> *fileName) {
return get(fileName->data(), fileName->cap()); return get(fileName->data(), fileName->cap());
} }
/** /**
* @return 0 if no error * @return 0 if no error
*/ */
Error PathIterator::next(BString<MaxFileNameLength> *fileName) { Error PathIterator::next(IString<MaxFileNameLength> *fileName) {
return next(fileName->data(), fileName->cap()); return next(fileName->data(), fileName->cap());
} }

View File

@ -13,7 +13,7 @@
namespace ox { namespace ox {
constexpr std::size_t MaxFileNameLength = 255; constexpr std::size_t MaxFileNameLength = 255;
using FileName = BString<MaxFileNameLength>; using FileName = IString<MaxFileNameLength>;
class PathIterator { class PathIterator {
private: private:

View File

@ -34,7 +34,7 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
using BuffPtr_t = uint32_t; using BuffPtr_t = uint32_t;
ox::Vector<char> buff(5 * ox::units::MB); ox::Vector<char> buff(5 * ox::units::MB);
auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer<BuffPtr_t, NodeType<BuffPtr_t>>(buff.size()); auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer<BuffPtr_t, NodeType<BuffPtr_t>>(buff.size());
using String = ox::BString<6>; using String = ox::IString<6>;
auto a1 = buffer->malloc(sizeof(String)).value; auto a1 = buffer->malloc(sizeof(String)).value;
auto a2 = buffer->malloc(sizeof(String)).value; auto a2 = buffer->malloc(sizeof(String)).value;
oxAssert(a1.valid(), "Allocation 1 failed."); oxAssert(a1.valid(), "Allocation 1 failed.");

View File

@ -77,7 +77,7 @@ class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<R
constexpr Error field(const char*, BasicString<SmallStringSize> *val) noexcept; constexpr Error field(const char*, BasicString<SmallStringSize> *val) noexcept;
template<std::size_t L> template<std::size_t L>
constexpr Error field(const char*, BString<L> *val) noexcept; constexpr Error field(const char*, IString<L> *val) noexcept;
constexpr Error fieldCString(const char*, char *val, std::size_t buffLen) noexcept; constexpr Error fieldCString(const char*, char *val, std::size_t buffLen) noexcept;
@ -336,7 +336,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, BasicString<
template<Reader_c Reader> template<Reader_c Reader>
template<std::size_t L> template<std::size_t L>
constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, BString<L> *val) noexcept { constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, IString<L> *val) noexcept {
return fieldCString(name, val->data(), val->cap()); return fieldCString(name, val->data(), val->cap());
} }

View File

@ -27,7 +27,7 @@ struct TestStructNest {
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
bool Bool = false; bool Bool = false;
uint32_t Int = 0; uint32_t Int = 0;
ox::BString<32> BString = ""; ox::IString<32> IString = "";
}; };
struct TestStruct { struct TestStruct {
@ -46,7 +46,7 @@ struct TestStruct {
int unionIdx = 1; int unionIdx = 1;
TestUnion Union; TestUnion Union;
ox::String String; ox::String String;
ox::BString<32> BString = ""; ox::IString<32> IString = "";
uint32_t List[4] = {0, 0, 0, 0}; uint32_t List[4] = {0, 0, 0, 0};
ox::Vector<uint32_t> Vector = {1, 2, 3, 4, 5}; ox::Vector<uint32_t> Vector = {1, 2, 3, 4, 5};
ox::Vector<uint32_t> Vector2 = {1, 2, 3, 4, 5}; ox::Vector<uint32_t> Vector2 = {1, 2, 3, 4, 5};
@ -72,7 +72,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) noexcep
oxModelBegin(TestStructNest) oxModelBegin(TestStructNest)
oxModelField(Bool) oxModelField(Bool)
oxModelField(Int) oxModelField(Int)
oxModelField(BString) oxModelField(IString)
oxModelEnd() oxModelEnd()
template<typename T> template<typename T>
@ -95,7 +95,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexce
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx})); oxReturnError(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx}));
} }
oxReturnError(io->field("String", &obj->String)); oxReturnError(io->field("String", &obj->String));
oxReturnError(io->field("BString", &obj->BString)); oxReturnError(io->field("IString", &obj->IString));
oxReturnError(io->field("List", obj->List, 4)); oxReturnError(io->field("List", obj->List, 4));
oxReturnError(io->field("Vector", &obj->Vector)); oxReturnError(io->field("Vector", &obj->Vector));
oxReturnError(io->field("Vector2", &obj->Vector2)); oxReturnError(io->field("Vector2", &obj->Vector2));
@ -127,7 +127,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
TestStruct testIn, testOut; TestStruct testIn, testOut;
testIn.Bool = true; testIn.Bool = true;
testIn.Int = 42; testIn.Int = 42;
testIn.BString = "Test String 1"; testIn.IString = "Test String 1";
testIn.String = "Test String 2"; testIn.String = "Test String 2";
testIn.Vector = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, }; testIn.Vector = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, };
testIn.Vector2 = {}; testIn.Vector2 = {};
@ -137,7 +137,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
testIn.List[3] = 4; testIn.List[3] = 4;
testIn.Struct.Bool = true; testIn.Struct.Bool = true;
testIn.Struct.Int = 300; testIn.Struct.Int = 300;
testIn.Struct.BString = "Test String 3"; testIn.Struct.IString = "Test String 3";
testIn.unionIdx = 1; testIn.unionIdx = 1;
testIn.Union.Int = 93; testIn.Union.Int = 93;
// run tests // run tests
@ -157,7 +157,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testIn.Int8 == testOut.Int8, "Int8 value mismatch"); oxAssert(testIn.Int8 == testOut.Int8, "Int8 value mismatch");
oxAssert(testIn.Union.Int == testOut.Union.Int, "Union.Int value mismatch"); oxAssert(testIn.Union.Int == testOut.Union.Int, "Union.Int value mismatch");
oxAssert(testIn.String == testOut.String, "String value mismatch"); oxAssert(testIn.String == testOut.String, "String value mismatch");
oxAssert(testIn.BString == testOut.BString, "BString value mismatch"); oxAssert(testIn.IString == testOut.IString, "IString value mismatch");
oxAssert(testIn.List[0] == testOut.List[0], "List[0] value mismatch"); oxAssert(testIn.List[0] == testOut.List[0], "List[0] value mismatch");
oxAssert(testIn.List[1] == testOut.List[1], "List[1] value mismatch"); oxAssert(testIn.List[1] == testOut.List[1], "List[1] value mismatch");
oxAssert(testIn.List[2] == testOut.List[2], "List[2] value mismatch"); oxAssert(testIn.List[2] == testOut.List[2], "List[2] value mismatch");
@ -171,9 +171,9 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testIn.Map["aoeu"] == testOut.Map["aoeu"], "Map[\"aoeu\"] value mismatch"); oxAssert(testIn.Map["aoeu"] == testOut.Map["aoeu"], "Map[\"aoeu\"] value mismatch");
oxAssert(testIn.EmptyStruct.Bool == testOut.EmptyStruct.Bool, "EmptyStruct.Bool value mismatch"); oxAssert(testIn.EmptyStruct.Bool == testOut.EmptyStruct.Bool, "EmptyStruct.Bool value mismatch");
oxAssert(testIn.EmptyStruct.Int == testOut.EmptyStruct.Int, "EmptyStruct.Int value mismatch"); oxAssert(testIn.EmptyStruct.Int == testOut.EmptyStruct.Int, "EmptyStruct.Int value mismatch");
oxAssert(testIn.EmptyStruct.BString == testOut.EmptyStruct.BString, "EmptyStruct.BString value mismatch"); oxAssert(testIn.EmptyStruct.IString == testOut.EmptyStruct.IString, "EmptyStruct.IString value mismatch");
oxAssert(testIn.Struct.Int == testOut.Struct.Int, "Struct.Int value mismatch"); oxAssert(testIn.Struct.Int == testOut.Struct.Int, "Struct.Int value mismatch");
oxAssert(testIn.Struct.BString == testOut.Struct.BString, "Struct.BString value mismatch"); oxAssert(testIn.Struct.IString == testOut.Struct.IString, "Struct.IString value mismatch");
oxAssert(testIn.Struct.Bool == testOut.Struct.Bool, "Struct.Bool value mismatch"); oxAssert(testIn.Struct.Bool == testOut.Struct.Bool, "Struct.Bool value mismatch");
return OxError(0); return OxError(0);
} }
@ -303,14 +303,14 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
TestStruct testIn; TestStruct testIn;
testIn.Bool = true; testIn.Bool = true;
testIn.Int = 42; testIn.Int = 42;
testIn.BString = "Test String 1"; testIn.IString = "Test String 1";
testIn.List[0] = 1; testIn.List[0] = 1;
testIn.List[1] = 2; testIn.List[1] = 2;
testIn.List[2] = 3; testIn.List[2] = 3;
testIn.List[3] = 4; testIn.List[3] = 4;
testIn.Struct.Bool = true; testIn.Struct.Bool = true;
testIn.Struct.Int = 300; testIn.Struct.Int = 300;
testIn.Struct.BString = "Test String 2"; testIn.Struct.IString = "Test String 2";
testIn.unionIdx = 1; testIn.unionIdx = 1;
testIn.Union.Int = 93; testIn.Union.Int = 93;
oxAssert(ox::writeMC(dataBuff.data(), dataBuff.size(), testIn), "Data generation failed"); oxAssert(ox::writeMC(dataBuff.data(), dataBuff.size(), testIn), "Data generation failed");
@ -322,7 +322,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(ox::readMC(dataBuff.data(), dataBuff.size(), &testOut), "Data read failed"); oxAssert(ox::readMC(dataBuff.data(), dataBuff.size(), &testOut), "Data read failed");
oxAssert(testOut.at("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed"); oxAssert(testOut.at("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed");
oxAssert(testOut.at("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed"); oxAssert(testOut.at("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed");
oxAssert(testOut.at("BString").unwrap()->get<ox::String>() == testIn.BString.c_str(), "testOut.String failed"); oxAssert(testOut.at("IString").unwrap()->get<ox::String>() == testIn.IString.c_str(), "testOut.String failed");
oxAssert(testOut.at("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed"); oxAssert(testOut.at("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed");
auto &testOutStruct = testOut.at("Struct").unwrap()->get<ox::ModelObject>(); auto &testOutStruct = testOut.at("Struct").unwrap()->get<ox::ModelObject>();
auto &testOutUnion = testOut.at("Union").unwrap()->get<ox::ModelUnion>(); auto &testOutUnion = testOut.at("Union").unwrap()->get<ox::ModelUnion>();
@ -333,14 +333,14 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(testOutStruct.typeName() == TestStructNest::TypeName, "ModelObject TypeName failed"); oxAssert(testOutStruct.typeName() == TestStructNest::TypeName, "ModelObject TypeName failed");
oxAssert(testOutStruct.typeVersion() == TestStructNest::TypeVersion, "ModelObject TypeVersion failed"); oxAssert(testOutStruct.typeVersion() == TestStructNest::TypeVersion, "ModelObject TypeVersion failed");
oxAssert(testOutStruct.at("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool failed"); oxAssert(testOutStruct.at("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool failed");
oxAssert(testOutStruct.at("BString").unwrap()->get<ox::String>() == testIn.Struct.BString.c_str(), "testOut.Struct.BString failed"); oxAssert(testOutStruct.at("IString").unwrap()->get<ox::String>() == testIn.Struct.IString.c_str(), "testOut.Struct.IString failed");
oxAssert(testOut.at("unionIdx").unwrap()->get<int>() == testIn.unionIdx, "testOut.unionIdx failed"); oxAssert(testOut.at("unionIdx").unwrap()->get<int>() == testIn.unionIdx, "testOut.unionIdx failed");
oxAssert(testOutUnion.unionIdx() == testIn.unionIdx, "testOut.Union idx wrong"); oxAssert(testOutUnion.unionIdx() == testIn.unionIdx, "testOut.Union idx wrong");
oxAssert(testOutUnion.at("Int").unwrap()->get<uint32_t>() == testIn.Union.Int, "testOut.Union.Int failed"); oxAssert(testOutUnion.at("Int").unwrap()->get<uint32_t>() == testIn.Union.Int, "testOut.Union.Int failed");
oxAssert(testOutList[0].get<uint32_t>() == testIn.List[0], "testOut.List[0] failed"); oxAssert(testOutList[0].get<uint32_t>() == testIn.List[0], "testOut.List[0] failed");
oxAssert(testOutList[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] failed"); oxAssert(testOutList[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] failed");
oxAssert(testOutStructCopy.at("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool (copy) failed"); oxAssert(testOutStructCopy.at("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool (copy) failed");
oxAssert(testOutStructCopy.at("BString").unwrap()->get<ox::String>() == testIn.Struct.BString.c_str(), "testOut.Struct.BString (copy) failed"); oxAssert(testOutStructCopy.at("IString").unwrap()->get<ox::String>() == testIn.Struct.IString.c_str(), "testOut.Struct.IString (copy) failed");
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed"); oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed"); oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
return OxError(0); return OxError(0);
@ -357,14 +357,14 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
TestStruct testIn, testOut; TestStruct testIn, testOut;
testIn.Bool = true; testIn.Bool = true;
testIn.Int = 42; testIn.Int = 42;
testIn.BString = "Test String 1"; testIn.IString = "Test String 1";
testIn.List[0] = 1; testIn.List[0] = 1;
testIn.List[1] = 2; testIn.List[1] = 2;
testIn.List[2] = 3; testIn.List[2] = 3;
testIn.List[3] = 4; testIn.List[3] = 4;
testIn.Struct.Bool = false; testIn.Struct.Bool = false;
testIn.Struct.Int = 300; testIn.Struct.Int = 300;
testIn.Struct.BString = "Test String 2"; testIn.Struct.IString = "Test String 2";
oxAssert(ox::writeMC(dataBuff, dataBuffLen, testIn), "Data generation failed"); oxAssert(ox::writeMC(dataBuff, dataBuffLen, testIn), "Data generation failed");
ox::TypeStore typeStore; ox::TypeStore typeStore;
const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn); const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn);

View File

@ -66,7 +66,7 @@ class MetalClawWriter {
constexpr Error field(const char*, const BasicString<SmallStringSize> *val) noexcept; constexpr Error field(const char*, const BasicString<SmallStringSize> *val) noexcept;
template<std::size_t L> template<std::size_t L>
constexpr Error field(const char*, const BString<L> *val) noexcept; constexpr Error field(const char*, const IString<L> *val) noexcept;
constexpr Error fieldCString(const char *name, const char *const*val, std::size_t buffLen) noexcept; constexpr Error fieldCString(const char *name, const char *const*val, std::size_t buffLen) noexcept;
@ -206,7 +206,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const BasicString<Sm
template<Writer_c Writer> template<Writer_c Writer>
template<std::size_t L> template<std::size_t L>
constexpr Error MetalClawWriter<Writer>::field(const char *name, const BString<L> *val) noexcept { constexpr Error MetalClawWriter<Writer>::field(const char *name, const IString<L> *val) noexcept {
return fieldCString(name, val->data(), val->cap()); return fieldCString(name, val->data(), val->cap());
} }

View File

@ -9,7 +9,7 @@
#pragma once #pragma once
#include <ox/std/byteswap.hpp> #include <ox/std/byteswap.hpp>
#include <ox/std/bstring.hpp> #include <ox/std/istring.hpp>
#include <ox/std/memory.hpp> #include <ox/std/memory.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <ox/std/trace.hpp> #include <ox/std/trace.hpp>
@ -152,7 +152,7 @@ class TypeDescWriter {
template<std::size_t sz> template<std::size_t sz>
[[nodiscard]] [[nodiscard]]
constexpr const DescriptorType *type(const BString<sz> *val) const noexcept; constexpr const DescriptorType *type(const IString<sz> *val) const noexcept;
template<typename T> template<typename T>
[[nodiscard]] [[nodiscard]]
@ -334,7 +334,7 @@ constexpr const DescriptorType *TypeDescWriter::type(const char*) const noexcept
} }
template<std::size_t sz> template<std::size_t sz>
constexpr const DescriptorType *TypeDescWriter::type(const BString<sz>*) const noexcept { constexpr const DescriptorType *TypeDescWriter::type(const IString<sz>*) const noexcept {
constexpr auto PT = PrimitiveType::String; constexpr auto PT = PrimitiveType::String;
return getType(types::BString, 0, PT, 0); return getType(types::BString, 0, PT, 0);
} }

View File

@ -9,7 +9,7 @@
#pragma once #pragma once
#include <ox/std/byteswap.hpp> #include <ox/std/byteswap.hpp>
#include <ox/std/bstring.hpp> #include <ox/std/istring.hpp>
#include <ox/std/memory.hpp> #include <ox/std/memory.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <ox/std/trace.hpp> #include <ox/std/trace.hpp>

View File

@ -151,15 +151,15 @@ template<typename T, typename Str = const char*>
constexpr auto ModelTypeVersionStr_v = [] { constexpr auto ModelTypeVersionStr_v = [] {
constexpr auto version = ModelTypeVersion_v<T>; constexpr auto version = ModelTypeVersion_v<T>;
constexpr auto versionStr = ox::sfmt("{}", version); constexpr auto versionStr = ox::sfmt("{}", version);
return ox::BString<versionStr.len()>{versionStr}; return ox::IString<versionStr.len()>{versionStr};
}; };
template<typename T> template<typename T>
constexpr auto ModelTypeId_v = [] { constexpr auto ModelTypeId_v = [] {
constexpr auto name = ModelTypeName_v<T, ox::StringView>; constexpr auto name = ModelTypeName_v<T, ox::StringView>;
constexpr auto version = ModelTypeVersion_v<T>; constexpr auto version = ModelTypeVersion_v<T>;
constexpr auto versionStr = ox::sfmt<ox::BString<19>>("{}", version); constexpr auto versionStr = ox::sfmt<ox::IString<19>>("{}", version);
return ox::sfmt<ox::BString<name.len() + versionStr.len() + 1>>("{};{}", name, versionStr); return ox::sfmt<ox::IString<name.len() + versionStr.len() + 1>>("{};{}", name, versionStr);
}(); }();
} }

View File

@ -21,7 +21,7 @@
#endif #endif
#include <ox/std/array.hpp> #include <ox/std/array.hpp>
#include <ox/std/bstring.hpp> #include <ox/std/istring.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <ox/std/strops.hpp> #include <ox/std/strops.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>

View File

@ -70,7 +70,7 @@ class OrganicClawReader {
Error field(const char *key, BasicString<L> *val) noexcept; Error field(const char *key, BasicString<L> *val) noexcept;
template<std::size_t L> template<std::size_t L>
Error field(const char *key, BString<L> *val) noexcept; Error field(const char *key, IString<L> *val) noexcept;
Error fieldCString(const char *key, char *val, std::size_t buffLen) noexcept; Error fieldCString(const char *key, char *val, std::size_t buffLen) noexcept;
@ -206,7 +206,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
} }
template<std::size_t L> template<std::size_t L>
Error OrganicClawReader::field(const char *key, BString<L> *val) noexcept { Error OrganicClawReader::field(const char *key, IString<L> *val) noexcept {
return fieldCString(key, val->data(), val->cap()); return fieldCString(key, val->data(), val->cap());
} }

View File

@ -35,7 +35,7 @@ struct TestStructNest {
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
bool Bool = false; bool Bool = false;
uint32_t Int = 0; uint32_t Int = 0;
ox::BString<32> String = ""; ox::IString<32> String = "";
}; };
struct TestStruct { struct TestStruct {

View File

@ -132,7 +132,7 @@ class OrganicClawWriter {
} }
template<std::size_t L> template<std::size_t L>
Error field(char const*key, BString<L> const*val) noexcept { Error field(char const*key, IString<L> const*val) noexcept {
if (targetValid() && val->len()) { if (targetValid() && val->len()) {
value(key) = val->c_str(); value(key) = val->c_str();
} }

View File

@ -90,7 +90,7 @@ install(
assert.hpp assert.hpp
bit.hpp bit.hpp
bounds.hpp bounds.hpp
bstring.hpp istring.hpp
buffer.hpp buffer.hpp
buildinfo.hpp buildinfo.hpp
byteswap.hpp byteswap.hpp

View File

@ -9,7 +9,7 @@
#pragma once #pragma once
#include "basestringview.hpp" #include "basestringview.hpp"
#include "bstring.hpp" #include "istring.hpp"
#include "string.hpp" #include "string.hpp"
#include "stringliteral.hpp" #include "stringliteral.hpp"
@ -27,7 +27,7 @@ class CStringView: public detail::BaseStringView {
constexpr CStringView(BasicString<SmallStrSz> const&str) noexcept: BaseStringView(str.data(), str.len()) {} constexpr CStringView(BasicString<SmallStrSz> const&str) noexcept: BaseStringView(str.data(), str.len()) {}
template<std::size_t SmallStrSz> template<std::size_t SmallStrSz>
constexpr CStringView(BString<SmallStrSz> const&str) noexcept: BaseStringView(str.data(), str.len()) {} constexpr CStringView(IString<SmallStrSz> const&str) noexcept: BaseStringView(str.data(), str.len()) {}
constexpr CStringView(std::nullptr_t) noexcept {} constexpr CStringView(std::nullptr_t) noexcept {}

View File

@ -19,7 +19,7 @@
#include "realstd.hpp" #include "realstd.hpp"
#include "error.hpp" #include "error.hpp"
#include "ignore.hpp" #include "ignore.hpp"
#include "bstring.hpp" #include "istring.hpp"
#include "string.hpp" #include "string.hpp"
#include "strops.hpp" #include "strops.hpp"
#include "types.hpp" #include "types.hpp"
@ -39,7 +39,7 @@ constexpr StringView toStringView(const char *s) noexcept {
} }
template<bool force = false, std::size_t size> template<bool force = false, std::size_t size>
constexpr StringView toStringView(const BString<size> &s) noexcept { constexpr StringView toStringView(const IString<size> &s) noexcept {
return s.c_str(); return s.c_str();
} }

View File

@ -16,40 +16,41 @@
namespace ox { namespace ox {
// Bounded String // Inline String
template<std::size_t buffLen> template<std::size_t buffLen>
class BString { class IString {
private: private:
char m_buff[buffLen + 1]; char m_buff[buffLen + 1];
size_t m_size{};
public: public:
constexpr BString() noexcept; constexpr IString() noexcept;
constexpr BString(StringView str) noexcept; constexpr IString(StringView str) noexcept;
constexpr BString(const char *str) noexcept; constexpr IString(const char *str) noexcept;
constexpr BString &operator=(CRStringView str) noexcept; constexpr IString &operator=(CRStringView str) noexcept;
constexpr BString &operator=(const char *str) noexcept; constexpr IString &operator=(const char *str) noexcept;
constexpr BString &operator=(char *str) noexcept; constexpr IString &operator=(char *str) noexcept;
constexpr BString &operator=(Integer_c auto i) noexcept; constexpr IString &operator=(Integer_c auto i) noexcept;
constexpr BString &operator+=(const char *str) noexcept; constexpr IString &operator+=(const char *str) noexcept;
constexpr BString &operator+=(char *str) noexcept; constexpr IString &operator+=(char *str) noexcept;
constexpr BString &operator+=(Integer_c auto i) noexcept; constexpr IString &operator+=(Integer_c auto i) noexcept;
constexpr BString &operator+=(StringView s) noexcept; constexpr IString &operator+=(StringView s) noexcept;
constexpr BString operator+(const char *str) const noexcept; constexpr IString operator+(const char *str) const noexcept;
constexpr BString operator+(char *str) const noexcept; constexpr IString operator+(char *str) const noexcept;
constexpr BString operator+(Integer_c auto i) 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;
@ -94,83 +95,85 @@ class BString {
}; };
template<std::size_t size> template<std::size_t size>
constexpr BString<size>::BString() noexcept: m_buff{{0}} { constexpr IString<size>::IString() noexcept: m_buff{{0}} {
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size>::BString(StringView str) noexcept: m_buff{{0}} { constexpr IString<size>::IString(StringView str) noexcept: m_buff{{0}} {
operator=(str); operator=(str);
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size>::BString(const char *str) noexcept: m_buff{{0}} { constexpr IString<size>::IString(const char *str) noexcept: m_buff{{0}} {
operator=(str); operator=(str);
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> &BString<size>::operator=(Integer_c auto i) noexcept { constexpr IString<size> &IString<size>::operator=(Integer_c auto i) noexcept {
char str[65] = {}; char str[65] = {};
ox::itoa(i, str); ox::itoa(i, str);
return this->operator=(str); return this->operator=(str);
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> &BString<size>::operator=(ox::CRStringView str) noexcept { constexpr IString<size> &IString<size>::operator=(ox::CRStringView str) noexcept {
std::size_t strLen = str.bytes() + 1; std::size_t strLen = str.bytes() + 1;
if (cap() < strLen) { if (cap() < strLen) {
strLen = cap(); strLen = cap();
} }
ox::memcpy(m_buff, str.data(), strLen); m_size = 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;
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> &BString<size>::operator=(const char *str) noexcept { constexpr IString<size> &IString<size>::operator=(const char *str) noexcept {
std::size_t strLen = ox::strlen(str) + 1; std::size_t strLen = ox::strlen(str) + 1;
if (cap() < strLen) { if (cap() < strLen) {
strLen = cap(); strLen = cap();
} }
ox::memcpy(m_buff, str, strLen); m_size = 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;
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> &BString<size>::operator=(char *str) noexcept { 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> template<std::size_t size>
constexpr BString<size> &BString<size>::operator+=(const char *str) noexcept { constexpr IString<size> &IString<size>::operator+=(const char *str) noexcept {
std::size_t strLen = ox::strlen(str) + 1; std::size_t strLen = ox::strlen(str) + 1;
std::ignore = append(str, strLen); std::ignore = append(str, strLen);
return *this; return *this;
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> &BString<size>::operator+=(char *str) noexcept { 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> template<std::size_t size>
constexpr BString<size> &BString<size>::operator+=(Integer_c auto i) noexcept { constexpr IString<size> &IString<size>::operator+=(Integer_c auto i) noexcept {
char str[65] = {}; char str[65] = {};
ox::itoa(i, str); ox::itoa(i, str);
return this->operator+=(str); return this->operator+=(str);
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> &BString<size>::operator+=(StringView s) noexcept { constexpr IString<size> &IString<size>::operator+=(StringView s) noexcept {
std::size_t strLen = s.bytes(); std::size_t strLen = s.bytes();
std::ignore = append(s.data(), strLen); std::ignore = append(s.data(), strLen);
return *this; return *this;
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> BString<size>::operator+(const char *str) const noexcept { constexpr IString<size> IString<size>::operator+(const char *str) const noexcept {
auto out = *this; auto out = *this;
std::size_t strLen = ox::strlen(str) + 1; std::size_t strLen = ox::strlen(str) + 1;
std::ignore = out.append(str, strLen); std::ignore = out.append(str, strLen);
@ -178,49 +181,49 @@ constexpr BString<size> BString<size>::operator+(const char *str) const noexcept
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> BString<size>::operator+(char *str) const noexcept { constexpr IString<size> IString<size>::operator+(char *str) const noexcept {
return *this + static_cast<const char*>(str); return *this + static_cast<const char*>(str);
} }
template<std::size_t size> template<std::size_t size>
constexpr BString<size> BString<size>::operator+(Integer_c auto i) const noexcept { constexpr IString<size> IString<size>::operator+(Integer_c auto i) const noexcept {
char str[65] = {}; char str[65] = {};
ox::itoa(i, str); ox::itoa(i, str);
return this->operator+(str); return this->operator+(str);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr bool BString<buffLen>::operator==(const char *other) const noexcept { constexpr bool IString<buffLen>::operator==(const char *other) const noexcept {
return ox::StringView(*this) == other; return ox::StringView(*this) == other;
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr bool BString<buffLen>::operator==(const OxString_c auto &other) const noexcept { constexpr bool IString<buffLen>::operator==(const OxString_c auto &other) const noexcept {
return ox::StringView(*this) == ox::StringView(other); return ox::StringView(*this) == ox::StringView(other);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr bool BString<buffLen>::operator!=(const char *other) const noexcept { constexpr bool IString<buffLen>::operator!=(const char *other) const noexcept {
return !operator==(other); return !operator==(other);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr bool BString<buffLen>::operator!=(const OxString_c auto &other) noexcept { constexpr bool IString<buffLen>::operator!=(const OxString_c auto &other) noexcept {
return !operator==(other); return !operator==(other);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr char BString<buffLen>::operator[](std::size_t i) const noexcept { constexpr char IString<buffLen>::operator[](std::size_t i) const noexcept {
return m_buff[i]; return m_buff[i];
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr char &BString<buffLen>::operator[](std::size_t i) noexcept { constexpr char &IString<buffLen>::operator[](std::size_t i) noexcept {
return m_buff[i]; return m_buff[i];
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr Error BString<buffLen>::append(const char *str, std::size_t strLen) noexcept { constexpr Error IString<buffLen>::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) {
@ -234,23 +237,23 @@ constexpr Error BString<buffLen>::append(const char *str, std::size_t strLen) no
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr const char *BString<buffLen>::data() const noexcept { constexpr const char *IString<buffLen>::data() const noexcept {
return static_cast<const char*>(m_buff); return static_cast<const char*>(m_buff);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr char *BString<buffLen>::data() noexcept { constexpr char *IString<buffLen>::data() noexcept {
return static_cast<char*>(m_buff); return static_cast<char*>(m_buff);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr const char *BString<buffLen>::c_str() const noexcept { constexpr const char *IString<buffLen>::c_str() const noexcept {
return static_cast<const char*>(m_buff); return static_cast<const char*>(m_buff);
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr std::size_t BString<buffLen>::len() const noexcept { constexpr std::size_t IString<buffLen>::len() const noexcept {
std::size_t length = 0; std::size_t length = 0;
for (std::size_t i = 0; i < buffLen; i++) { for (std::size_t i = 0; i < buffLen; i++) {
uint8_t b = static_cast<uint8_t>(m_buff[i]); uint8_t b = static_cast<uint8_t>(m_buff[i]);
@ -268,14 +271,14 @@ constexpr std::size_t BString<buffLen>::len() const noexcept {
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr std::size_t BString<buffLen>::bytes() const noexcept { constexpr std::size_t IString<buffLen>::bytes() const noexcept {
std::size_t i = 0; std::size_t i = 0;
for (i = 0; i < buffLen && m_buff[i]; i++); for (i = 0; i < buffLen && m_buff[i]; i++);
return i + 1; // add one for null terminator return i + 1; // add one for null terminator
} }
template<std::size_t buffLen> template<std::size_t buffLen>
constexpr std::size_t BString<buffLen>::cap() const noexcept { constexpr std::size_t IString<buffLen>::cap() const noexcept {
return buffLen; return buffLen;
} }

View File

@ -13,7 +13,7 @@
#include "assert.hpp" #include "assert.hpp"
#include "bit.hpp" #include "bit.hpp"
#include "bounds.hpp" #include "bounds.hpp"
#include "bstring.hpp" #include "istring.hpp"
#include "byteswap.hpp" #include "byteswap.hpp"
#include "concepts.hpp" #include "concepts.hpp"
#include "cstringview.hpp" #include "cstringview.hpp"

View File

@ -32,8 +32,7 @@ class StringLiteral: public detail::BaseStringView {
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {} constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
template<size_t Sz> constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {
constexpr explicit StringLiteral(char const (&str)[Sz]) noexcept: StringLiteral(str, Sz) {
} }
constexpr auto &operator=(StringLiteral const&other) noexcept { constexpr auto &operator=(StringLiteral const&other) noexcept {

View File

@ -20,7 +20,7 @@
namespace ox { namespace ox {
template<std::size_t buffLen> template<std::size_t buffLen>
class BString; class IString;
template<std::size_t buffLen> template<std::size_t buffLen>
class BasicString; class BasicString;
@ -41,7 +41,7 @@ class StringView: public detail::BaseStringView {
constexpr StringView(const BasicString<SmallStrSz> &str) noexcept: BaseStringView(str.data(), str.len()) {} constexpr StringView(const BasicString<SmallStrSz> &str) noexcept: BaseStringView(str.data(), str.len()) {}
template<std::size_t SmallStrSz> template<std::size_t SmallStrSz>
constexpr StringView(const BString<SmallStrSz> &str) noexcept: BaseStringView(str.data(), str.len()) {} constexpr StringView(const IString<SmallStrSz> &str) noexcept: BaseStringView(str.data(), str.len()) {}
constexpr StringView(std::nullptr_t) noexcept {} constexpr StringView(std::nullptr_t) noexcept {}

View File

@ -68,7 +68,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
{ {
"BString", "BString",
[]() { []() {
ox::BString<5> s; ox::IString<5> s;
s += "A"; s += "A";
s += "B"; s += "B";
s += 9; s += 9;

View File

@ -12,7 +12,7 @@
#include <array> #include <array>
#endif #endif
#include "bstring.hpp" #include "istring.hpp"
#include "def.hpp" #include "def.hpp"
#include "fmt.hpp" #include "fmt.hpp"
#include "hashmap.hpp" #include "hashmap.hpp"
@ -182,7 +182,7 @@ class OutStream {
} }
template<std::size_t sz> template<std::size_t sz>
constexpr OutStream &operator<<(const BString<sz> &v) noexcept { constexpr OutStream &operator<<(const IString<sz> &v) noexcept {
return operator<<(v.c_str()); return operator<<(v.c_str());
} }

View File

@ -272,7 +272,7 @@ constexpr bool is_move_constructible_v = detail::is_move_constructible<T>(0);
template<std::size_t SmallStringSize> template<std::size_t SmallStringSize>
class BasicString; class BasicString;
template<std::size_t sz> template<std::size_t sz>
class BString; class IString;
class CStringView; class CStringView;
class StringLiteral; class StringLiteral;
class StringView; class StringView;
@ -289,7 +289,7 @@ constexpr auto isOxString(const BasicString<sz>*) noexcept {
} }
template<std::size_t sz> template<std::size_t sz>
constexpr auto isOxString(const BString<sz>*) noexcept { constexpr auto isOxString(const IString<sz>*) noexcept {
return true; return true;
} }

View File

@ -9,7 +9,7 @@
#pragma once #pragma once
#include "array.hpp" #include "array.hpp"
#include "bstring.hpp" #include "istring.hpp"
#include "buffer.hpp" #include "buffer.hpp"
#include "random.hpp" #include "random.hpp"
#include "ranges.hpp" #include "ranges.hpp"
@ -17,7 +17,7 @@
namespace ox { namespace ox {
using UUIDStr = ox::BString<36>; using UUIDStr = ox::IString<36>;
namespace detail { namespace detail {
@ -61,7 +61,7 @@ constexpr ox::Result<uint8_t> fromHex(ox::CRStringView v) noexcept {
return out; return out;
} }
constexpr ox::BString<2> toHex(uint8_t v) noexcept { constexpr ox::IString<2> toHex(uint8_t v) noexcept {
constexpr ox::Array<char, 16> valMap { constexpr ox::Array<char, 16> valMap {
'0', '0',
'1', '1',