Class holding information about a string, with ownership over the data. More...
Public Member Functions | |
String () noexcept | |
String (const char *data) noexcept | |
String (unsigned long long size) noexcept | |
String (const char *data, unsigned long long size) noexcept | |
String (StringView view) noexcept | |
String (const String &other) noexcept | |
String (String &&other) noexcept | |
~String () | |
char * | getData () const |
unsigned long long | getSize () const |
bool | empty () const |
char | front () const |
char & | front () |
char | back () const |
char & | back () |
const char * | begin () const |
char * | begin () |
const char * | end () const |
char * | end () |
void | clear () |
void | resize (unsigned long long size) |
BufferCast< StringView > | split (StringView separator) |
String & | operator= (const char *data) noexcept |
String & | operator= (StringView other) noexcept |
String & | operator= (const String &other) noexcept |
String & | operator= (String &&other) noexcept |
char | operator[] (unsigned long long index) const |
char & | operator[] (unsigned long long index) |
void | operator+= (char value) |
void | operator+= (StringView other) |
String | operator+ (char c) const |
String | operator+ (const char *other) const |
String | operator+ (StringView other) const |
bool | operator== (const char *other) const |
bool | operator== (StringView other) const |
bool | operator!= (const char *other) const |
bool | operator!= (StringView other) const |
template<typename T = std::string> | |
String (const std::string &str) noexcept | |
template<typename T = std::string_view> | |
String (const std::string_view &str) noexcept | |
operator std::string () const | |
operator std::string_view () const | |
operator nkLog::String () const | |
operator nkLog::StringView () const | |
String & | operator= (const std::string &data) |
String & | operator= (const std::string_view &data) |
Class holding information about a string, with ownership over the data.
This class will abstract a chain of characters and offer some utility to help manipulating them. The aim of this class is not to replace std::string within a codebase, but rather to offer a safe data exchange class from an app to the dlls, and the other way around. This class being fully exported, it doesn't suffer from the caveats a template can have in such situations.
To help in this dialog between app and dlls, the class is thought to be as transparent as possible between const char*, std::string and other widespread way of representing strings. Typical usage would just be to use standard structures in your app and benefit from the automatic converions from one type to another.
The String class will copy over memory and keep it in its own safe allocation. If memory safety is required, use this class. However, this can be slower as memory needs to be allocated and shuffled around. Unless this is required, prefer to use the StringView variant.
|
noexcept |
Default constructor. Will default to a nullptr data and a size of 0.
|
noexcept |
Const char* constructor. Provided memory location will be copied based on its length. Be sure provided data is null-terminated.
data | The pointer to the chain of characters to take over. |
|
noexcept |
Pre-allocation constructor. Data will be allocated depending on the size requested, and set to 0.
size | The size of the chain to create, in number of chars. |
|
noexcept |
Guided const char* constructor. Provided memory location will be copied based on the size given. Prefer this constructor over the const char* constructor if you know the size required.
data | The pointer to the chain of characters to take over. |
size | The size of the chain provided, in number of chars. |
|
noexcept |
View constructor. Memory location pointed by view will be copied over.
view | The view to copy the memory from. |
|
noexcept |
Copy constructor.
other | The string to copy from. |
|
noexcept |
Move constructor.
other | The string to move over. |
nkMemory::String::~String | ( | ) |
Destructor.
|
noexcept |
Standard string constructor. The string provided will be copied over.
str | The string to copy. |
|
noexcept |
Standard string view constructor. The view provided will be copied over.
str | The view to copy. |
char* nkMemory::String::getData | ( | ) | const |
unsigned long long nkMemory::String::getSize | ( | ) | const |
bool nkMemory::String::empty | ( | ) | const |
char nkMemory::String::front | ( | ) | const |
char& nkMemory::String::front | ( | ) |
char nkMemory::String::back | ( | ) | const |
char& nkMemory::String::back | ( | ) |
const char* nkMemory::String::begin | ( | ) | const |
char* nkMemory::String::begin | ( | ) |
const char* nkMemory::String::end | ( | ) | const |
char* nkMemory::String::end | ( | ) |
void nkMemory::String::clear | ( | ) |
Clears the string and frees its memory, returning it to its default state.
void nkMemory::String::resize | ( | unsigned long long | size | ) |
Resizes the internal memory of the string. Existing chars will be kept, while newly introduced ones will be set to 0.
size | The new size the string should take, in number of chars. |
BufferCast<StringView> nkMemory::String::split | ( | StringView | separator | ) |
Splits a string into multiple tokens.
separator | The separator pattern to use to split the string. |
|
noexcept |
Const char* assignment operator.
data | The pointer over the memory to copy. |
|
noexcept |
View assignment operator.
other | The view over memory to copy. |
String copy assignment operator.
other | The string to copy. |
String move assignment operator.
other | The string to move over. |
char nkMemory::String::operator[] | ( | unsigned long long | index | ) | const |
Const access operator.
index | The index of the char to access. |
char& nkMemory::String::operator[] | ( | unsigned long long | index | ) |
Access operator.
index | The index of the char to access. |
void nkMemory::String::operator+= | ( | char | value | ) |
Char append operator.
value | The char to append to the string. |
void nkMemory::String::operator+= | ( | StringView | other | ) |
View append operator.
other | The view to append to the string. |
String nkMemory::String::operator+ | ( | char | c | ) | const |
Char concatenation operator.
c | The char to concatenate. |
String nkMemory::String::operator+ | ( | const char * | other | ) | const |
Char chain concatenation operator.
other | The chain to concatenate with. |
String nkMemory::String::operator+ | ( | StringView | other | ) | const |
View concatenation operator.
other | The view to concatenate with. |
bool nkMemory::String::operator== | ( | const char * | other | ) | const |
Const char* equality operator.
other | The const char* to check equality with. |
bool nkMemory::String::operator== | ( | StringView | other | ) | const |
View equality operator.
other | The view to check equality with. |
bool nkMemory::String::operator!= | ( | const char * | other | ) | const |
Const char* inequality operator.
other | The const char* to check equality with. |
bool nkMemory::String::operator!= | ( | StringView | other | ) | const |
View inequality operator.
other | The view to check equality with. |
nkMemory::String::operator std::string | ( | ) | const |
Conversion operator, to std::string.
nkMemory::String::operator std::string_view | ( | ) | const |
Conversion operator, to std::string_view.
nkMemory::String::operator nkLog::String | ( | ) | const |
Conversion operator, to nkLog::String.
nkMemory::String::operator nkLog::StringView | ( | ) | const |
Conversion operator, to nkLog::StringView.
String& nkMemory::String::operator= | ( | const std::string & | data | ) |
Templated assignment operator.
data | The string to assign. |
String& nkMemory::String::operator= | ( | const std::string_view & | data | ) |
Templated assignment operator.
data | The string view to assign. |