From 02332d99b530fedefc3bd13bef8844ff95a9029f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 20 Jan 2026 00:26:38 -0600 Subject: [PATCH] [ox] Fix issues in String Types section of docs --- deps/ox/ox-docs.md | 58 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/deps/ox/ox-docs.md b/deps/ox/ox-docs.md index d0dbe93a..76e412b6 100644 --- a/deps/ox/ox-docs.md +++ b/deps/ox/ox-docs.md @@ -191,9 +191,13 @@ maintain a reference to the data. Views should be used where you otherwise might use a const reference to a string store type. +Having all of these different string types may sound like an interoperability +nightmare, but taking string view types extensively where applicable makes the +imagined interoperability issues virtually non-existent. + #### String Store Types -##### String +##### String / BasicString ```ox::String```, or really ```ox::BasicString```, is Ox's version of ```std::string```. @@ -209,7 +213,7 @@ small string buffers. // s can hold up to 100 bytes, plus one for a null terminator before allocating ox::BasicString<100> s; ``` -Also ulike ```std::string```, ```String``` has an explicit C-string conversion +Also unlike ```std::string```, ```ox::String``` has an explicit C-string conversion constructor. This prevents accidental instantiations of ```String```. @@ -241,6 +245,46 @@ s = "12345"; // valid s = "123456"; // will compile and run, but will get cut off at '5' ``` +This is useful for certain string categories that have fixed lengths, like UUID +strings or for numbers. + +Ox makes use of ```IString``` in the following ways: + +```cpp +using UUIDStr = ox::IString<36>; + +// and + +template +[[nodiscard]] +constexpr auto intToStr(Integer v) noexcept { + constexpr auto Cap = [] { + auto out = 0; + switch (sizeof(Integer)) { + case 1: + out = 4; + break; + case 2: + out = 6; + break; + case 4: + out = 11; + break; + case 8: + out = 22; + break; + } + return out + ox::is_signed_v; + }(); + ox::IString out; + std::ignore = out.resize(out.cap()); + ox::CharBuffWriter w{{out.data(), out.cap()}}; + std::ignore = writeItoa(v, w); + std::ignore = out.resize(w.tellp()); + return out; +} +``` + ##### StringParam ```StringParam``` is a weird type. @@ -264,13 +308,14 @@ void f() { ``` ```StringParam``` has implicit conversion constructors, and will appropriately -move from r-value ```String```s. -It will create a ```String``` if not passed ownership of an existing -```String```. +move from r-value ```String```s or create a ```String``` if not passed +ownership of an existing ```String```. +Think of ```StringParam``` as a way to opt-in to implicit instantiation with +strings. ```StringParam``` can access the string as a view through the ```view()``` function, and the ```String``` inside can be accessed by moving from the -```StringParams```. +```StringParam```. ```cpp struct Type { @@ -337,6 +382,7 @@ There are a few convenience aliases as well. * StringCR = String const& * StringViewCR = StringView const& * CStringViewCR = CStringView const& +* CString = const char* String views do not generally need const references, but it does make debugging easier, as we can skip the constructor call if a string view already exists.