4#include "../Common/StringSpan.h"
5#include "../Memory/Buffer.h"
6#include "../Memory/Memory.h"
31 String(StringEncoding encoding = StringEncoding::Utf8) : encoding(encoding) {}
36 String(StringSpan sv) { SC_MEMORY_ASSERT_RELEASE(assign(sv)); }
49 SC_MEMORY_ASSERT_RELEASE(assign(StringSpan({text, N - 1},
true, StringEncoding::Ascii)));
55 [[nodiscard]]
bool owns(StringSpan view)
const;
61 [[nodiscard]]
bool assign(StringSpan sv);
65 [[nodiscard]] StringEncoding
getEncoding()
const {
return encoding; }
77 [[nodiscard]]
bool isEmpty()
const {
return data.isEmpty(); }
81 [[nodiscard]] StringSpan
view() const SC_LANGUAGE_LIFETIME_BOUND;
86 [[nodiscard]]
bool operator==(const
String& other)
const {
return view() == (other.view()); }
91 [[nodiscard]]
bool operator!=(
const String& other)
const {
return not operator==(other); }
96 [[nodiscard]]
bool operator==(
const StringSpan other)
const {
return view() == (other); }
101 [[nodiscard]]
bool operator!=(
const StringSpan other)
const {
return not operator==(other); }
110 return view() == other;
119 return view() != other;
125 [[nodiscard]]
bool operator<(
const StringSpan other)
const {
return view() < other; }
135 SC_MEMORY_ASSERT_RELEASE(assign(StringSpan({text, N - 1},
true, StringEncoding::Ascii)));
146 friend struct StringTest;
147 template <
typename T>
148 friend struct Reflection::Reflect;
150 template <
typename T>
151 friend struct GrowableBuffer;
156 IGrowableBuffer::DirectAccess& da;
160 void finalize()
noexcept;
161 bool tryGrowTo(
size_t newSize)
noexcept;
164 StringEncoding encoding;
167 String(StringEncoding encoding, uint32_t inlineCapacity);
168 String(
Buffer&& otherData, StringEncoding encoding, uint32_t inlineCapacity);
177 SmallString(StringEncoding encoding = StringEncoding::Utf8) :
String(encoding, N) {}
181 String& operator=(
SmallString&& other) {
return String::operator=(move(other)); }
192 uint64_t inlineCapacity = N;
202struct SC_MEMORY_EXPORT GrowableBuffer<
String> :
public IGrowableBuffer
205 GrowableBuffer(
String&
string)
206 : IGrowableBuffer(&GrowableBuffer::tryGrowTo), gi(
string, IGrowableBuffer::directAccess)
208 static bool tryGrowTo(IGrowableBuffer& gb,
size_t newSize)
noexcept
210 return static_cast<GrowableBuffer&
>(gb).gi.tryGrowTo(newSize);
212 static auto getEncodingFor(
const String& str)
noexcept {
return str.
getEncoding(); }
213 void finalize()
noexcept { gi.finalize(); }
217struct SC_MEMORY_EXPORT GrowableBuffer<
SmallString<N>> :
public IGrowableBuffer
220 GrowableBuffer(
String&
string)
221 : IGrowableBuffer(&GrowableBuffer::tryGrowTo), gi(
string, IGrowableBuffer::directAccess)
223 static bool tryGrowTo(IGrowableBuffer& gb,
size_t newSize)
noexcept
225 return static_cast<GrowableBuffer&
>(gb).gi.tryGrowTo(newSize);
228 void finalize()
noexcept { gi.finalize(); }
An heap allocated byte buffer that can optionally use an inline buffer.
Definition Buffer.h:30
String with compile time configurable inline storage (small string optimization)
Definition String.h:175
A non-modifiable owning string with associated encoding.
Definition String.h:28
StringEncoding getEncoding() const
Get StringSpan encoding.
Definition String.h:65
bool operator!=(const String &other) const
Check if current String is different from other String.
Definition String.h:91
bool operator<(const StringSpan other) const
Check if current String is smaller to another StringView (using StringView::compare)
Definition String.h:125
bool operator!=(const char(&other)[N]) const
Check if current String is different from the ascii string literal.
Definition String.h:117
StringSpan view() const SC_LANGUAGE_LIFETIME_BOUND
Obtain a null-terminated StringSpan from current String.
String(const char(&text)[N])
Builds String with a null terminated char string literal.
Definition String.h:47
bool owns(StringSpan view) const
Checks if the memory pointed by the StringSpan is owned by this String.
size_t sizeInBytesIncludingTerminator() const
Get length of the string in bytes (including null terminator bytes)
Definition String.h:69
String(StringEncoding encoding=StringEncoding::Utf8)
Builds an empty String with a given Encoding.
Definition String.h:31
bool operator!=(const StringSpan other) const
Check if current String is different from other StringSpan.
Definition String.h:101
String & operator=(const char(&text)[N])
Assigns an ascii string literal to current String.
Definition String.h:133
bool assign(StringSpan sv)
Assigns a StringSpan to this String, replacing existing contents.
bool operator==(const StringSpan other) const
Check if current String is same as other StringSpan.
Definition String.h:96
String & operator=(StringSpan view)
Assigns (copy) contents of given StringSpan in current String.
bool isEmpty() const
Check if String is empty.
Definition String.h:77
const char * bytesIncludingTerminator() const
Access current string content as read-only null-terminated const char*
Definition String.h:73
String(Buffer &&otherData, StringEncoding encoding)
Builds a String from a buffer ensuring zero termination.
String(StringSpan sv)
Builds String from a StringSpan.
Definition String.h:36
bool operator==(const char(&other)[N]) const
Check if current String is equal to the ascii string literal.
Definition String.h:108