MD::StringVariant Class

template <typename String, typename StringView> class MD::StringVariant

String variant that may holds string or string view. More...

Header: #include <md4qt/traits.h>
CMake: find_package(md4qt REQUIRED COMPONENTS md4qt)
target_link_libraries(mytarget PRIVATE md4qt::md4qt)

Public Functions

StringVariant()
StringVariant(const String &s)
StringVariant(const StringView &v)
void clear()
MD::StringVariant<String, StringView> &insert(long long pos, const String &what)
bool isEmpty() const
long long length() const
MD::StringVariant<String, StringView> &remove(long long pos, long long size)
MD::StringVariant<String, StringView> sliced(long long pos, long long n) const
String toString() const
typename String::value_type operator[](long long pos) const

Detailed Description

String variant that may holds string or string view. Modifications are allowed even if it holds string view - in this case will be made deep copy to string from view, and modifications will be made on copied string.

Member Function Documentation

StringVariant::StringVariant()

Default constructor of empty string variant.

StringVariant::StringVariant(const String &s)

Constructor from string.

StringVariant::StringVariant(const StringView &v)

Constructor from string view.

void StringVariant::clear()

Clear this string variant to default empty state.

MD::StringVariant<String, StringView> &StringVariant::insert(long long pos, const String &what)

Insert string at the given position.

pos Position.

what A string to insert.

bool StringVariant::isEmpty() const

Returns whether this string is empty.

long long StringVariant::length() const

Returns length of the string.

MD::StringVariant<String, StringView> &StringVariant::remove(long long pos, long long size)

Removes from the given position the given count of characters.

pos Position.

size Count of characters.

MD::StringVariant<String, StringView> StringVariant::sliced(long long pos, long long n) const

Returns sliced of this string variant. Doesn't do any copying.

pos Start position.

n Count of characters.

String StringVariant::toString() const

Returns deep copy of the string.

typename String::value_type StringVariant::operator[](long long pos) const

Returns character at the given position.

pos Position.