- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
The `utf::string` class API
- Member types
- 
Public member functions
- 
Constructors
- string ()
- string (string const&)
- string (string&&)
- string (const char*)
- string (view const&)
- string (string::char_type, string::size_type)
- from_bytes (std::vector<uint8_t> const&) -> string
- from_unicode (std::initializer_list<string::char_type>) -> string
- from_std_string (std::string const&) -> string
 
- Destructor
- Convertors
- 
Transforming algorithms
- clear () -> string&
- erase (string::size_type, string::size_type) -> string&
- erase (string_view const&) -> string&
- erase (string_view::iterator const&) -> string&
- insert (string::size_type, string::char_type) -> string&
- insert (string::size_type, string_view const&) -> string&
- insert (string_view::iterator const&, string::char_type) -> string&
- insert (string_view::iterator const&, string_view const&) -> string&
- pop () -> string::char_type
- push (string::char_type) -> string&
- push (string_view const&) -> string&
- remove_if (Functor&&) -> string&
- remove (string::char_type, Char...) -> string&
- remove (string_view const&, View const&...) -> string&
- replace_all_if (Functor&&, string::char_type) -> string&
- replace_all (string::char_type, string::char_type) -> string&
- replace_all (string_view const&, string_view const&) -> string&
- replace (string::size_type, string::size_type, string_view const&) -> string&
- replace (string::size_type, string_view const&) -> string&
- replace (string_view const&, string_view const&) -> string&
- replace (string_view::iterator const&, string_view const&) -> string&
- reserve (string::size_type) -> string&
- shrink_to_fit () -> string&
- simplify () -> string&
- split_off (string::size_type) -> string
- to_lower_ascii () -> string&
- to_upper_ascii () -> string&
- trim_if (Functor&&) -> string&
- trim () -> string&
- trim (string::char_type) -> string&
 
 
- 
Constructors
Default constructor. Does not allocate any memory in the heap.
Copy constructor.
Move constructor.
Converting constructor from a C-string.
Converting constructor from a string view. The effect is equivalent to invoke view::to_string ().
Constructs a string as a copy of Ch character N times.
Converting constructor from a vector of UTF-8 bytes. For example,
utf::string::from_bytes({ 0b11000010, 0b10100101, '1', '0' })is equal to "¥10".
Converting constructor from a list of Unicode codepoints. For example,
utf::string::from_unicode({ 0xA5, '1', '0' });is equal to "¥10".
Converting constructor from an STL string object.
Frees an allocated memory chunk.
Creates and returns an std::vector object containing UTF-8-encoded bytes of the string.
Creates and returns an std::vector object containing the Unicode codepoints of the string's characters.
Returns the copy of the original string. Useful for chaining, e.g.,
auto ModifiedCopy = StayOriginal.clone().insert(5, "substring");Creates an iterable span over entire string.
This is an
O(1)operation.
Creates an iterable span over a substring in range [shift; shift + N). If N > this->length() - shift, takes all characters to a string's end.
⚠ Throws:
- 
utf::invalid_argumentifshiftis negative;
- 
utf::length_errorifNis negative.
Creates an iterable span over N first characters of a string.
⚠ Throws utf::length_error if N is negative.
Creates an iterable span over N last characters of a string.
⚠ Throws utf::length_error if N is negative.
Completely clears the string by deallocating its owned memory.
Returns *this.
Removes N characters starting from the given index pos.
⚠ Throws:
- 
utf::invalid_argumentifposis negative;
- 
utf::length_errorifNis negative.
Returns *this.
Removes all characters in the given range.
⚠ Throws utf::out_of_range if vi ⊄ *this.
Returns *this.
Removes one character by an iterator iter.
⚠ Throws utf::out_of_range if iter ∉ *this.
Returns *this.
Inserts a character ucode into the string before the pos-th.
⚠ Throws:
- 
utf::invalid_argumentifposis negative;
- 
utf::unicode_errorin case ofucode's invalid codepoint.
Returns *this.
Inserts a substring into the string before the pos-th.
⚠ Throws utf::invalid_argument if pos is negative.
Returns *this.
Inserts a character ucode into the string before the character pointing by iter.
⚠ Throws:
- 
utf::out_of_rangeifiter∉*this;
- 
utf::unicode_errorin case ofucode's invalid codepoint.
Returns *this.
Inserts a substring into the string before the character pointing by iter.
⚠ Throws utf::out_of_range if iter ∉ *this.
Returns *this.
Removes the last character from the string and returns its codepoint.
⚠ Throws utf::underflow_error if *this was empty before modifying.
Appends a given Unicode character to the end of the string.
⚠ Throws utf::unicode_error in case of ucode's invalid codepoint.
Returns *this.
Appends a given substring to the end of current string.
Returns *this.
Removes all characters satisfying specified criteria from the string.
Template constraints:
- 
std::is_invocable<Functor, string::char_type>;
- 
std::predicate<Functor, string::char_type>.
Returns *this.
Removes all occurrences of the every character in the string.
Template constraints:
- 
std::is_convertible<Char, string::char_type>...;
- 
std::convertible_to<Char, string::char_type>....
⚠ Throws utf::unicode_error in case of any character's invalid codepoint.
Returns *this.
Removes all occurences of the every substring in the string.
Template constraints:
- 
std::is_convertible<View, string_view>...;
- 
std::convertible_to<View, string_view>....
Returns *this.
Replaces all characters satisfying specified criteria by another one.
Template constraints:
- 
std::is_invocable<Functor, string::char_type>;
- 
std::predicate<Functor, string::char_type>.
⚠ Throws utf::unicode_error in case of ucode's invalid codepoint.
Returns *this.
Replaces all occurences of the character what by ucode.
⚠ Throws utf::unicode_error in case of ucode's/what's invalid codepoint.
Returns *this.
Replaces all occurences of the substring vi by other.
Returns *this.
Replaces N characters starting from the given index pos by other substring.
⚠ Throws:
- 
utf::invalid_argumentifposis negative;
- 
utf::length_errorifNis negative.
Returns *this.
Replaces all characters starting from the given index pos by other substring.
❗ Note that the behavior of this function may change in the future.
⚠ Throws utf::invalid_argument if pos is negative.
Returns *this.
Replaces the characters in the given range by other substring.
⚠ Throws utf::out_of_range if vi ⊄ *this.
Returns *this.
Replaces a character (by its iterator) by a new substring.
❗ Note that the behavior of this function may change in the future.
⚠ Throws utf::out_of_range if iter ∉ *this.
Returns *this.
Checks the current capacity of the string and reallocates if it's less than ordered. For example:
utf::string Str { "Errare humanum est" };
assert(Str.capacity() == 18);
assert(Str.reserve(50).capacity() == 50);    // Good
//assert(Str.reserve(30).capacity() == 30);  // No way!
assert(Str.reserve(30).capacity() == 50);    // Same as beforeReturns *this.
Reallocates the memory buffer to make capacity() == size(). For example:
utf::string Str { "Errare humanum est" };
Str.reserve(50);    // Now, the capacity is 50
assert(Str.shrink_to_fit().capacity() == 18);   // Same as beforeReturns *this.
Removes the whitespaces from the start and the end and replaces all sequences of internal whitespace with a single space.
Returns *this.
Splits the string into 2 strings at specified position pos.
⚠ Throws utf::invalid_argument if pos is negative.
Returns right side-copy of original string, length length() - pos. If pos >= length(), returns an empty string.
Converts all ASCII characters in the string into its lowercase.
Returns *this.
Converts all ASCII characters in the string into its uppercase.
Returns *this.
Removes all characters satisfying specified criteria from both sides of the string.
Template constraints:
- 
std::is_invocable<Functor, string::char_type>;
- 
std::predicate<Functor, string::char_type>.
Returns *this.
Removes all whitespace-like characters from both sides of the string.
The effect is equivalent to trim(utf::is_space).
Returns *this.
Removes all occurrences of the given character from both sides of the string.
⚠ Throws utf::unicode_error in case of ucode's invalid codepoint.
Returns *this.