IndexContainersBLString
BLString Class Referencefinal

Byte string [C++ API].

Blend2D always uses UTF-8 encoding in public APIs so all strings are assumed UTF-8 by default. However, BLString doesn't guarantee any assumptions about the encoding of the data it holds. It can hold arbitrary byte sequence and act as a raw byte-string when this functionality is desired.

Member Functions

Construction & Destruction
Overloaded Operators
Common Functionality
Accessors
Data Manipulation
Equality & Comparison
Search

Additional Inherited Members

- Public Attributes inherited from BLObjectCore

BLString::BLString()noexcept[1/5][¶]

Creates an empty string.

BLString::BLString(
BLString&& other
)noexcept[2/5][¶]

Move constructor.

Note
The other string is always reset by a move construction, so it becomes an empty string.

BLString::BLString(
const BLString& other
)noexcept[3/5][¶]

Copy constructor, performs weak copy of the data held by the other string.

BLString::BLString()explicitnoexcept[4/5][¶]

Constructor that creates a string from the given string view.

Note
See other constructors for more details.

BLString::BLString(
const char* str,
size_t size = SIZE_MAX
)explicitnoexcept[5/5][¶]

Constructor that creates a string from the given data specified by str and size. If size is SIZE_MAX the string is assumed to be null terminated.

This is a convenience function that doesn't provide error handling. If size exceeds small string capacity and dynamic allocation failed then a default empty string would be constructed.

BLString::~BLString()noexcept[¶]

Destroys the string.

BLString::operator bool() constexplicitnoexcept[¶]

Tests whether the string has a content.

Note
This is essentially the opposite of empty().

BLString& BLString::operator=(
BLString&& other
)noexcept[1/2][¶]

Move assignment.

Note
The other string is reset by move construction, so it becomes an empty string.

BLString& BLString::operator=(
const BLString& other
)noexcept[2/2][¶]

Copy assignment, performs weak copy of the data held by the other string.

const char& BLString::operator[](
size_t index
) constnoexcept[¶]

Returns a character at the given index.

Note
This is the same as calling at(index).

BLResult BLString::reset()noexcept[¶]

Clears the content of the string and releases its data.

After reset the string content matches a default constructed string.

void BLString::swap(
BLString& other
)noexcept[¶]

Swaps the content of this string with the other string.

bool BLString::empty() constnoexcept[¶]

Tests whether the string is empty (has no content).

Returns true if the string's length is zero.

const char& BLString::at(
size_t index
) constnoexcept[¶]

Returns a character at the given index.

Note
Index must be valid and cannot be out of bounds - there is an assertion.

size_t BLString::size() constnoexcept[¶]

Returns the size of the string [in bytes].

size_t BLString::capacity() constnoexcept[¶]

Returns the capacity of the string [in bytes].

const char* BLString::data() constnoexcept[¶]

Returns a pointer to the data of the string.

const char* BLString::begin() constnoexcept[¶]

Returns a pointer to the beginning of string data (iterator compatibility).

const char* BLString::end() constnoexcept[¶]

Returns a pointer to the end of string data (iterator compatibility).

The returned pointer points to the string null terminator.

BLStringView BLString::view() constnoexcept[¶]

Returns the content of the string as BLStringView.

BLResult BLString::clear()noexcept[¶]

Clears the content of the string without releasing its dynamically allocated data, if possible.

BLResult BLString::shrink()noexcept[¶]

Shrinks the capacity of the string to match the actual content.

BLResult BLString::reserve(
size_t n
)noexcept[¶]

Reserves at least n bytes in the string for further manipulation (most probably appending).

BLResult BLString::resize(
size_t n,
char fill = '\0'
)noexcept[¶]

Resizes the string to n and fills the additional data by fill pattern.

BLResult BLString::makeMutable(
char** dataOut
)noexcept[¶]

Makes the string mutable.

This operation checks whether the string is mutable and if not it makes a deep copy of its content so it can be modified. Please note that you can only modify the content that is defined by its length property. Even if the string had higher capacity before makeMutable() it's not guaranteed that the possible new data would match that capacity.

If you want to make the string mutable for the purpose of appending or making other modifications please consider using modifyOp() and insertOp() instead.

BLResult BLString::assign(
char c,
size_t n = 1
)noexcept[1/5][¶]

Replaces the content of the string by c character or multiple characters if n is greater than one.

BLResult BLString::assign(
BLString&& other
)noexcept[2/5][¶]

Move assignment, the same as operator=(), but returns a BLResult instead of this.

BLResult BLString::assign(
const BLString& other
)noexcept[3/5][¶]

Copy assignment, the same as operator=(), but returns a BLResult instead of this.

BLResult BLString::assign()noexcept[4/5][¶]

Replaces the string by the content described by the given string view.

BLResult BLString::assign(
const char* str,
size_t n = SIZE_MAX
)noexcept[5/5][¶]

Replaces the string by str data of the given length n.

Note
The implementation assumes null terminated string if n equals to SIZE_MAX.

BLResult BLString::assignDeep(
const BLString& other
)noexcept[¶]

Copy assignment, but creates a deep copy of the other string instead of weak copy.

template<typename... Args>
BLResult BLString::assignFormat(
const char* fmt,
Args&&... args
)noexcept[¶]

Replaces the content of the string by a result of calling snprintf(fmt, args...).

BLResult BLString::assignFormatV(
const char* fmt,
va_list ap
)noexcept[¶]

Replaces the content of the string by a result of calling vsnprintf(fmt, ap).

BLResult BLString::truncate(
size_t n
)noexcept[¶]

Truncates the string length to n.

It does nothing if the the string length is less than n.

bool BLString::equals(
const BLString& other
) constnoexcept[1/3][¶]

Returns whether this string and other are equal (i.e. their contents match).

bool BLString::equals() constnoexcept[2/3][¶]

Returns whether this string and other string view are equal.

bool BLString::equals(
const char* str,
size_t n = SIZE_MAX
) constnoexcept[3/3][¶]

Returns whether this string and the given string data str of length n are equal.

int BLString::compare(
const BLString& other
) constnoexcept[1/3][¶]

Compares this string with other and returns either -1, 0, or 1.

int BLString::compare() constnoexcept[2/3][¶]

Compares this string with other string view and returns either -1, 0, or 1.

int BLString::compare(
const char* str,
size_t n = SIZE_MAX
) constnoexcept[3/3][¶]

Compares this string with other string data and returns either -1, 0, or 1.

size_t BLString::indexOf(
char c
) constnoexcept[1/2][¶]

Returns the first index at which a given character c can be found in the string, or SIZE_MAX if not present.

size_t BLString::indexOf(
char c,
size_t fromIndex
) constnoexcept[2/2][¶]

Returns the index at which a given character c can be found in the string starting from fromIndex, or SIZE_MAX if not present.

size_t BLString::lastIndexOf(
char c
) constnoexcept[1/2][¶]

Returns the last index at which a given character c can be found in the string, or SIZE_MAX if not present.

size_t BLString::lastIndexOf(
char c,
size_t fromIndex
) constnoexcept[2/2][¶]

Returns the index at which a given character c can be found in the string starting from fromIndex and ending at 0, or SIZE_MAX if not present.