Luna::BasicString
The basic string implementation that is suitable for any character types.
template <typename _Char, typename _Alloc>
class Luna::BasicString
Static objects
-
A special value that usually represents the end of the string. The exact meaning of this value is content specific.
Member functions
-
Constructs one empty string.
-
BasicString(const allocator_type &alloc)
Constructs one empty string with an custom allocator.
-
BasicString(usize count, value_type ch, const allocator_type &alloc=allocator_type())
Constructs one string using
count
copies of characterch
. -
BasicString(const BasicString &rhs, usize pos, const allocator_type &alloc=allocator_type())
Constructs one string by coping characters in range from another string.
-
Constructs one string by coping characters from another string.
-
BasicString(const value_type *s, usize count, const allocator_type &alloc=allocator_type())
Constructs one string by coping characters from the provided character array.
-
BasicString(const value_type *s, const allocator_type &alloc=allocator_type())
Constructs one string by coping characters from the provided null-terminated C string. The length of the string is determined by the first null character.
-
BasicString(_InputIt first, _InputIt last, const allocator_type &alloc=allocator_type())
Constructs one string by coping characters from string specified by the iterator range.
-
BasicString(const BasicString &rhs)
Constructs one string by coping data from another string.
-
BasicString(const BasicString &rhs, const allocator_type &alloc)
Constructs one string by coping data from another string.
-
BasicString(BasicString &&rhs)
Constructs one string by moving data from another string.
-
BasicString(BasicString &&rhs, const allocator_type &alloc)
Constructs one string by moving data from another string.
-
BasicString(InitializerList< value_type > ilist, const allocator_type &alloc=allocator_type())
Constructs one string by coping characters from the initializer list.
-
BasicString< _Char, _Alloc > & operator=(const BasicString &rhs)
Assigns the string by coping data from another string.
-
BasicString< _Char, _Alloc > & operator=(BasicString &&rhs)
Assigns the string by moving data from another string.
-
BasicString< _Char, _Alloc > & operator=(const value_type *s)
Assigns the string by coping characters from the provided null-terminated C string. The length of the string is determined by the first null character.
-
BasicString< _Char, _Alloc > & operator=(value_type ch)
Assigns the string with the specified character. This operation behaves the same as
assign(1, ch)
. -
BasicString< _Char, _Alloc > & operator=(InitializerList< value_type > ilist)
Assigns the string by coping characters from the initializer list.
-
BasicString< _Char, _Alloc >::pointer data()
Gets one pointer to the underlying character data.
-
BasicString< _Char, _Alloc >::const_pointer data() const
Gets one constant pointer to the underlying character data.
-
BasicString< _Char, _Alloc >::const_pointer c_str() const
Gets a non-modifiable C string pointer to the characters stored by this string.
-
BasicString< _Char, _Alloc >::iterator begin()
Gets one iterator to the first character of this string.
-
BasicString< _Char, _Alloc >::iterator end()
Gets one iterator to the one-past-last character of this string.
-
BasicString< _Char, _Alloc >::const_iterator begin() const
Gets one constnat iterator to the first character of this string.
-
BasicString< _Char, _Alloc >::const_iterator end() const
Gets one constant iterator to the one-past-last character of this string.
-
BasicString< _Char, _Alloc >::const_iterator cbegin() const
Gets one constnat iterator to the first character of this string.
-
BasicString< _Char, _Alloc >::const_iterator cend() const
Gets one constant iterator to the one-past-last character of this string.
-
BasicString< _Char, _Alloc >::reverse_iterator rbegin()
Gets one reverse iterator to the last character of this string.
-
BasicString< _Char, _Alloc >::reverse_iterator rend()
Gets one reverse iterator to the one-before-first character of this string.
-
BasicString< _Char, _Alloc >::const_reverse_iterator rbegin() const
Gets one constant reverse iterator to the last character of this string.
-
BasicString< _Char, _Alloc >::const_reverse_iterator rend() const
Gets one constant reverse iterator to the one-before-first character of this string.
-
BasicString< _Char, _Alloc >::const_reverse_iterator crbegin() const
Gets one constant reverse iterator to the last character of this string.
-
BasicString< _Char, _Alloc >::const_reverse_iterator crend() const
Gets one constant reverse iterator to the one-before-first character of this string.
-
Gets the size of the string, that is, the number of characters in the string, excluding the null terminator.
-
Gets the size of the string, that is, the number of characters in the string, excluding the null terminator.
-
Gets the capacity of the string, that is, the maximum number of characters that can be stored in this string without reallocating the string buffer.
-
Checks whether this string is empty, that is, the size of this string is
0
. -
Increases the capacity of the string to a value greater than or equal to
new_cap
, so that it can hold at leastnew_cap
characters without reallocating the string buffer. -
void resize(usize n, value_type v)
Resizes the string.
-
Reduces the capacity of the string so that capacity == size.
-
BasicString< _Char, _Alloc >::reference operator[](usize n)
Gets the character at the specified index.
-
BasicString< _Char, _Alloc >::const_reference operator[](usize n) const
Gets the character at the specified index.
-
BasicString< _Char, _Alloc >::reference at(usize n)
Gets the character at the specified index.
-
BasicString< _Char, _Alloc >::const_reference at(usize n) const
Gets the character at the specified index.
-
BasicString< _Char, _Alloc >::reference front()
Gets the first character of the string.
-
BasicString< _Char, _Alloc >::const_reference front() const
Gets the first character of the string.
-
BasicString< _Char, _Alloc >::reference back()
Gets the last character of the string.
-
BasicString< _Char, _Alloc >::const_reference back() const
Gets the last character of the string.
-
Removes all characters from the string, but keeps the string buffer.
-
Pushes one character to the back of the string.
-
Removes the element from the back of the string.
-
void assign(usize count, value_type ch)
Assigns the string data by
count
copies ofch
. -
void assign(const BasicString &str)
Assigns the string data by coping characters from another string.
-
void assign(const BasicString &str, usize pos, usize count=npos)
Assigns the string data by coping characters from one subrange of another string.
-
void assign(BasicString &&str)
Assigns the string data by moving characters from another string.
-
void assign(const value_type *s, usize count)
Assigns the string data by coping characters from the provided character array.
-
void assign(const value_type *s)
Assigns the string data by coping characters from the provided null-terminated C string. The length of the string is determined by the first null character.
-
void assign(_InputIt first, _InputIt last)
Assigns the string data by coping characters from string specified by the iterator range.
-
void assign(InitializerList< value_type > ilist)
Assigns the string data by coping characters from the initializer list.
-
void insert(usize index, usize count, value_type ch)
Inserts
count
copies of characters in the specified position. -
void insert(usize index, const value_type *s)
Inserts one null-terminated C string at the specified position.
-
void insert(usize index, const value_type *s, usize count)
Inserts one character array at the specified position.
-
void insert(usize index, const BasicString &str)
Inserts another string at the specified position.
-
void insert(usize index, const BasicString &str, usize index_str, usize count=npos)
Inserts one subrange of another string at the specified position.
-
BasicString< _Char, _Alloc >::iterator insert(const_iterator pos, value_type ch)
Inserts one character at the specified position.
-
BasicString< _Char, _Alloc >::iterator insert(const_iterator pos, usize count, value_type ch)
Inserts
count
copies ofch
at the specified position. -
BasicString< _Char, _Alloc >::iterator insert(const_iterator pos, _InputIt first, _InputIt last)
Inserts characters from the iterator range at the specified position.
-
Inserts characters from the specified initializer list at the specified position.
-
void erase(usize index=0, usize count=npos)
Removes
count
characters from the specified position. -
BasicString< _Char, _Alloc >::iterator erase(const_iterator pos)
Removes one character.
-
BasicString< _Char, _Alloc >::iterator erase(const_iterator first, const_iterator last)
Removes characters in the specified range.
-
Swaps characters of this string with the specified string.
-
void append(usize count, value_type ch)
Appends
count
copies of characterch
to the back of the string. -
void append(const BasicString &str)
Appends another string to the back of the string.
-
void append(const BasicString &str, usize pos, usize count=npos)
Appends one subrange of another string to the back of the string.
-
void append(const value_type *s, usize count)
Appends one character array to the back of the string.
-
void append(const value_type *s)
Appends one null-terminated C string to the back of the string.
-
void append(_InputIt first, _InputIt last)
Appends characters from the iterator range to the back of the string.
-
void append(InitializerList< value_type > ilist)
Appends characters from the specified initializer list to the back of the string.
-
i32 compare(const BasicString &rhs) const
Compares this string with the specified string.
-
i32 compare(usize pos1, usize count1, const BasicString &rhs) const
Compares [
pos1
,pos1 + count1
) substring of this string torhs
. -
i32 compare(usize pos1, usize count1, const BasicString &rhs, usize pos2, usize count2=npos) const
Compares a [
pos1
,pos1 + count1
) substring of this string to a substring [pos2
,pos2 + count2
) ofrhs
. -
i32 compare(const value_type *s) const
Compares this string to the null-terminated C string.
-
i32 compare(usize pos1, usize count1, const value_type *s) const
Compares [
pos1
,pos1 + count1
) substring of this string to the null-terminated C string. -
i32 compare(usize pos1, usize count1, const value_type *s, usize count2) const
Compares [
pos1
,pos1 + count1
) substring of this string to the characters in the range [s
,s + count2
). -
void replace(usize pos, usize count, const BasicString &str)
Replaces characters in range [
pos
,pos + count
) with characters ofstr
. -
void replace(const_iterator first, const_iterator last, const BasicString &str)
Replaces characters in range [
first
,last
) with characters ofstr
. -
void replace(usize pos, usize count, const BasicString &str, usize pos2, usize count2=npos)
Replaces characters in range [
pos
,pos + count
) with a substring [pos2
,pos2 + count2
) ofstr
. -
void replace(const_iterator first, const_iterator last, _InputIt first2, _InputIt last2)
Replaces characters in range [
first
,last
) with the characters in the range [first2
,last2
). -
void replace(usize pos, usize count, const value_type *cstr, usize count2)
Replaces characters in range [
pos
,pos + count
) with a character array [cstr
,cstr + count2). @param[in] pos The index of the first character to replace. @param[in] count The number of characters to replace. If
pos + countis greater than
this->size(),
countwill be clamped to
this->size() - pos. @param[in] cstr The pointer to the character array to use for replacement. @param[in] count2 The number of characters in
cstrto use for replacement. @par Valid Usage *
posmust not be greater than
this->size()`. -
void replace(const_iterator first, const_iterator last, const value_type *cstr, usize count2)
Replaces characters in range [
first
,last
) with a character array [cstr
,cstr + count2). @param[in] first The iterator to the first character to replace. @param[in] last The iterator to the one-past-last character to replace. @param[in] cstr The pointer to the character array to use for replacement. @param[in] count2 The number of characters in
cstrto use for replacement. @par Valid Usage.
-
void replace(usize pos, usize count, const value_type *cstr)
Replaces characters in range [
pos
,pos + count
) with a null-terminated C string. -
void replace(const_iterator first, const_iterator last, const value_type *cstr)
Replaces characters in range [
first
,last
) with a null-terminated C string. -
void replace(usize pos, usize count, usize count2, value_type ch)
Replaces characters in range [
pos
,pos + count
) withcount2
copies of characterch
. -
void replace(const_iterator first, const_iterator last, usize count2, value_type ch)
Replaces characters in range [
first
,last
) withcount2
copies of characterch
. -
void replace(const_iterator first, const_iterator last, InitializerList< value_type > ilist)
Replaces characters in range [
first
,last
) with characters from the specified initializer list. -
BasicString< _Char, _Alloc > substr(usize pos=0, usize count=npos) const
Creates a substring of this string.
-
usize copy(value_type *dst, usize count, usize pos=0) const
Copies a substring [
pos
,pos + count
) to character string pointed to bydst
. -
BasicString< _Char, _Alloc >::allocator_type get_allocator() const
Gets the allocator of the string.
-
usize find(const BasicString &str, usize pos=0) const
Finds the first occurrence of the specified character sequence in the string.
-
usize find(const value_type *s, usize pos, usize count) const
Finds the first occurrence of the specified character sequence in the string.
-
usize find(const value_type *s, usize pos=0) const
Finds the first occurrence of the specified character sequence in the string.
-
usize find(value_type ch, usize pos=0) const
Finds the first occurrence of the specified character in the string.
-
usize rfind(const BasicString &str, usize pos=npos) const
Finds the last occurrence of the specified character sequence in the string.
-
usize rfind(const value_type *s, usize pos, usize count) const
Finds the last occurrence of the specified character sequence in the string.
-
usize rfind(const value_type *s, usize pos=0) const
Finds the last occurrence of the specified character sequence in the string.
-
usize rfind(value_type ch, usize pos=npos) const
Finds the first occurrence of the specified character in the string.