boost::text::basic_text
// In header: <boost/text/text.hpp> template<nf Normalization, typename Char, typename String> struct basic_text { // types typedef Char char_type; typedef String string; typedef basic_string_view< char_type > string_view; typedef basic_text_view< Normalization, char_type > text_view; typedef grapheme value_type; typedef std::size_t size_type; typedef unspecified iterator; typedef unspecified const_iterator; typedef stl_interfaces::reverse_iterator< iterator > reverse_iterator; typedef stl_interfaces::reverse_iterator< const_iterator > const_reverse_iterator; typedef typename iterator::reference reference; typedef typename const_iterator::reference const_reference; // construct/copy/destruct basic_text(); basic_text(basic_text const &) = default; basic_text(basic_text &&); basic_text(const_iterator, const_iterator); basic_text(char_type const *); explicit basic_text(text_view); explicit basic_text(rope_view); template<code_unit_range< utf_format > R> explicit basic_text(R const &); template<code_unit_iter< utf_format > I, std::sentinel_for< I > S> basic_text(I, S); template<grapheme_range_code_unit< utf_format > R> explicit basic_text(R const &); template<grapheme_iter_code_unit< utf_format > I> explicit basic_text(I, I); basic_text & operator=(basic_text const &) = default; basic_text & operator=(basic_text &&); basic_text & operator=(char_type const *); basic_text & operator=(string_view); basic_text & operator=(text_view); basic_text & operator=(rope_view); // public member functions BOOST_TEXT_STATIC_ASSERT_NORMALIZATION(); operator text_view() const; char_type * data(); char_type const * data() const; char_type const * c_str() const; const_reference front() const; const_reference back() const; reference front(); reference back(); void push_back(grapheme const &); template<typename CPIter> void push_back(grapheme_ref< CPIter >); void pop_back(); iterator begin(); iterator end(); const_iterator begin() const; const_iterator end() const; const_iterator cbegin() const; const_iterator cend() const; reverse_iterator rbegin(); reverse_iterator rend(); const_reverse_iterator rbegin() const; const_reverse_iterator rend() const; const_reverse_iterator crbegin() const; const_reverse_iterator crend() const; bool empty() const; size_type storage_code_units() const; size_type capacity_bytes() const; size_type distance() const; size_type max_code_units() const; void clear(); replace_result< iterator > erase(const_iterator, const_iterator); replace_result< iterator > erase(const_iterator); replace_result< iterator > replace(const_iterator, const_iterator, const_iterator, const_iterator); replace_result< iterator > replace(const_iterator, const_iterator, char_type const *); replace_result< iterator > replace(const_iterator, const_iterator, string_view); replace_result< iterator > replace(const_iterator, const_iterator, rope_view); template<code_unit_range< utf_format > R> replace_result< iterator > replace(const_iterator, const_iterator, R const &); template<code_unit_iter< utf_format > I> replace_result< iterator > replace(const_iterator, const_iterator, I, I); template<grapheme_range_code_unit< utf_format > R> replace_result< iterator > replace(const_iterator, const_iterator, R const &); template<grapheme_iter_code_unit< utf_format > I> replace_result< iterator > replace(const_iterator, const_iterator, I, I); replace_result< iterator > replace(const_iterator, const_iterator, grapheme const &); template<typename CPIter> replace_result< iterator > replace(const_iterator, const_iterator, grapheme_ref< CPIter >); replace_result< iterator > insert(const_iterator, const_iterator, const_iterator); template<typename T> auto insert(const_iterator, T const &); template<typename I> auto insert(const_iterator, I, I); void assign(const_iterator, const_iterator); template<typename T> auto assign(T const &); template<typename I> auto assign(I, I); void append(const_iterator, const_iterator); template<typename T> auto append(T const &); template<typename I> auto append(I, I); void reserve(size_type); void shrink_to_fit(); void swap(basic_text &); string extract(); void replace(string &&); template<typename T> auto operator+=(T const &); // friend functions std::ostream & operator<<(std::ostream &, basic_text const &); std::wostream & operator<<(std::wostream &, basic_text const &); template<typename T> bool operator==(basic_text const &, T const &); template<typename T> bool operator==(T const &, basic_text const &); template<typename T> bool operator!=(basic_text const &, T const &); template<typename T> bool operator!=(T const &, basic_text const &); // public data members static constexpr nf normalization; static constexpr format utf_format; };
A mutable sequence of graphemes over an underlying container of contiguous null-terminated code units. The underlying storage is a String
, and is kept in normalization form Normalization
. The String
is responsible for maintaining null-termination.
basic_text
public
typesThe type of code unit used in the underlying storage.
The type of the container used as underlying storage.
typedef basic_string_view< char_type > string_view;
The specialization of std::basic_string_view
(or boost::basic_string_view
in pre-C++17 code) compatible with string
.
typedef basic_text_view< Normalization, char_type > text_view;
The specialization of basic_text_view
with the same normalization form and underlying code unit type.
basic_text
public
construct/copy/destructbasic_text();
Default ctor.
basic_text(basic_text const &) = default;
basic_text(basic_text &&);
basic_text(const_iterator first, const_iterator last);
Constructs a
from a pair of iterators. basic_text
basic_text(char_type const * c_str);
Constructs a
from a null-terminated string. basic_text
explicit basic_text(text_view tv);
Constructs a
from a basic_text
text_view
.
explicit basic_text(rope_view rv);
Constructs a
from a basic_text
rope_view
.
template<code_unit_range< utf_format > R> explicit basic_text(R const & r);
Constructs a
from a range of basic_text
char_type
.
template<code_unit_iter< utf_format > I, std::sentinel_for< I > S> basic_text(I first, S last);
Constructs a
from a sequence of basic_text
char_type
.
template<grapheme_range_code_unit< utf_format > R> explicit basic_text(R const & r);
Constructs a
from a range of graphemes. basic_text
template<grapheme_iter_code_unit< utf_format > I> explicit basic_text(I first, I last);
Constructs a
from a sequence of graphemes. basic_text
basic_text & operator=(basic_text const &) = default;
basic_text & operator=(basic_text &&);
basic_text & operator=(char_type const * c_str);
Assignment from a null-terminated string.
basic_text & operator=(string_view sv);
Assignment from a string_view
.
basic_text & operator=(text_view tv);
Assignment from a text_view
.
basic_text & operator=(rope_view rv);
Assignment from a rope_view
.
basic_text
public member functionsBOOST_TEXT_STATIC_ASSERT_NORMALIZATION();
operator text_view() const;
char_type * data();
char_type const * data() const;
char_type const * c_str() const;
const_reference front() const;
const_reference back() const;
reference front();
reference back();
void push_back(grapheme const & g);
template<typename CPIter> void push_back(grapheme_ref< CPIter > g);
void pop_back();
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
bool empty() const;
Returns true iff size() == 0
.
size_type storage_code_units() const;
Returns the number of code units controlled by *this
, not including the null terminator.
size_type capacity_bytes() const;
Returns the number of bytes of storage currently in use by *this
.
size_type distance() const;
Returns the number of graphemes in *this
. This operation is O(n).
size_type max_code_units() const;
Returns the maximum size in code units a
can have. basic_text
void clear();
Clear.
Postconditions: |
size() == 0 && capacity() == 0; begin(), end() delimit an empty string |
replace_result< iterator > erase(const_iterator first, const_iterator last);
Erases the portion of *this
delimited by [first, last)
.
Requires: |
first <= last |
replace_result< iterator > erase(const_iterator at);
Erases the grapheme at position at
.
Requires: |
at != end() |
replace_result< iterator > replace(const_iterator first1, const_iterator last1, const_iterator first2, const_iterator last2);
Replaces the portion of *this
delimited by [first1, last1)
with the sequence [first2, last2)
.
Requires: |
!std::less(first1.base().base(), begin().base().base()) && !std::less(end().base().base(), last1.base().base()) |
replace_result< iterator > replace(const_iterator first, const_iterator last, char_type const * new_substr);
Replaces the portion of *this
delimited by [first, last)
with new_substr
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
replace_result< iterator > replace(const_iterator first, const_iterator last, string_view new_substr);
Replaves the portion of *this
delimited by [first, last)
with new_substr
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
replace_result< iterator > replace(const_iterator first, const_iterator last, rope_view new_substr);
Replaces the portion of *this
delimited by [first, last)
with new_substr
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
template<code_unit_range< utf_format > R> replace_result< iterator > replace(const_iterator first, const_iterator last, R const & r);
Replaces the portion of *this
delimited by [first, last)
with r
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
template<code_unit_iter< utf_format > I> replace_result< iterator > replace(const_iterator first1, const_iterator last1, I first2, I last2);
Replaces the portion of *this
delimited by [first1, last1)
with [first2, last2)
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
template<grapheme_range_code_unit< utf_format > R> replace_result< iterator > replace(const_iterator first, const_iterator last, R const & r);
Replaces the portion of *this
delimited by [first, last)
with r
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
template<grapheme_iter_code_unit< utf_format > I> replace_result< iterator > replace(const_iterator first1, const_iterator last1, I first2, I last2);
Replaces the portion of *this
delimited by [first1, last1)
with [first2, last2)
.
Requires: |
!std::less(first.base().base(), begin().base().base()) && !std::less(end().base().base(), last.base().base()) |
replace_result< iterator > replace(const_iterator first, const_iterator last, grapheme const & g);
Replaces the portion of *this
delimited by [first, last)
with g
.
template<typename CPIter> replace_result< iterator > replace(const_iterator first, const_iterator last, grapheme_ref< CPIter > g);
Replaces the portion of *this
delimited by [first, last)
with g
.
replace_result< iterator > insert(const_iterator at, const_iterator first, const_iterator last);
Inserts the sequence [first, last)
into *this
starting at position at
.
template<typename T> auto insert(const_iterator at, T const & x);
Inserts the sequence of char_type
from x
into *this
starting at position at
.
template<typename I> auto insert(const_iterator at, I first, I last);
Inserts the sequence [first, last)
into *this
starting at position at
.
void assign(const_iterator first, const_iterator last);
Assigns the sequence [first, last)
to *this
.
template<typename T> auto assign(T const & x);
Assigns the sequence of char_type
from x
to *this
.
template<typename I> auto assign(I first, I last);
Assigns the sequence [first, last)
to *this
.
void append(const_iterator first, const_iterator last);
Appends the sequence [first, last)
to *this
.
template<typename T> auto append(T const & x);
Appends the sequence of char_type
from x
to *this
.
template<typename I> auto append(I first, I last);
Appends the sequence [first, last)
to *this
.
void reserve(size_type new_size);
Reserves storage enough for a string of at least new_size
bytes.
Postconditions: |
capacity() >= new_size + 1 |
void shrink_to_fit();
Reduces storage used by *this
to just the amount necessary to contain size()
chars.
Postconditions: |
capacity() == 0 || capacity() == size() + 1 |
void swap(basic_text & rhs);
Swaps *this
with rhs.
string extract();
Removes and returns the underlying string from *this
.
void replace(string && s);
Replaces the underlying string in *this
.
Requires: |
s is in normalization form NFD or FCC. |
template<typename T> auto operator+=(T const & x);
Appends x
to *this
. T
may be any type for which *this = x
is well-formed.
basic_text
friend functionsstd::ostream & operator<<(std::ostream & os, basic_text const & t);
Stream inserter; performs formatted output, in UTF-8 encoding.
std::wostream & operator<<(std::wostream & os, basic_text const & t);
Stream inserter; performs formatted output, in UTF-16 encoding. Defined on Windows only.
template<typename T> bool operator==(basic_text const & lhs, T const & rhs);
Returns true iff lhs
== rhs
, where rhs
is an object for which lhs = rhs
is well-formed.
template<typename T> bool operator==(T const & lhs, basic_text const & rhs);
Returns true iff lhs
== rhs
, where rhs
is an object for which rhs = lhs
is well-formed.
template<typename T> bool operator!=(basic_text const & lhs, T const & rhs);
Returns true iff lhs
!= rhs
, where rhs
is an object for which lhs = rhs
is well-formed.
template<typename T> bool operator!=(T const & lhs, basic_text const & rhs);
Returns true iff lhs
!= rhs
, where rhs
is an object for which rhs = lhs
is well-formed.
basic_text
public
public data membersstatic constexpr nf normalization;
The normalization form used in this basic_text
.
static constexpr format utf_format;
The UTF format used in the underlying storage.