4#include "../Foundation/StringSpan.h"
5#include "../Memory/Buffer.h"
6#include "../Memory/Memory.h"
31 String(StringEncoding encoding = StringEncoding::Utf8) : encoding(encoding) {}
65 [[nodiscard]] StringEncoding
getEncoding()
const {
return encoding; }
77 [[nodiscard]]
bool isEmpty()
const {
return data.isEmpty(); }
86 [[nodiscard]]
bool operator==(const
String& other)
const {
return view() == (other.view()); }
91 [[nodiscard]]
bool operator!=(
const String& other)
const {
return not operator==(other); }
110 return view() == other;
119 return view() != other;
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;
177 SmallString(StringEncoding encoding = StringEncoding::Utf8) :
String(encoding, 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(); }
#define SC_ASSERT_RELEASE(e)
Assert expression e to be true.
Definition Assert.h:48
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition Compiler.h:273
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:33
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:29
char native_char_t
The native char for the platform (wchar_t (4 bytes) on Windows, char (1 byte) everywhere else )
Definition PrimitiveTypes.h:25
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
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37
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