nxt::utf8 namespace

Namespaces

namespace detail

Classes

struct byte_offset_t
Byte offset into a UTF-8 string.
struct grapheme_index_t
Grapheme-cluster index into a UTF-8 string.
class segment_view
Forward range over words and line breaks in a string view.
struct text_segment
Word or line-break segment used for streaming/wrapping text.
struct word
One non-separator word and its display width.
class word_view
Forward range over non-separator words in a string view.

Functions

auto byte_at(std::string_view text, grapheme_index_t cell) →  byte_offset_t noexcept
Byte offset at the cell-th grapheme cluster (clamped to text.size()).
auto byte_at_column(std::string_view text, width_t column) →  byte_offset_t noexcept
Byte offset for the grapheme cluster at column.
auto byte_offset(std::size_t n) →  byte_offset_t constexpr noexcept
Construct a byte offset.
auto cell_at(std::string_view text, byte_offset_t byte) →  grapheme_index_t noexcept
Grapheme cluster index for a byte offset, snapped to the previous boundary.
auto cluster_width(std::string_view cluster) →  width_t noexcept
Display width of one grapheme cluster.
auto column_at(std::string_view text, byte_offset_t byte) →  width_t noexcept
Display column for a byte offset, snapped to the previous boundary.
auto complete_words_prefix_size(std::string_view text) →  std::size_t noexcept
Size in bytes of the prefix that ends on a word boundary.
auto count(std::string_view text) →  grapheme_index_t noexcept
Number of grapheme clusters in text.
auto display_width(std::string_view text) →  width_t noexcept
Display width of all grapheme clusters in text.
auto floor_boundary(std::string_view text, byte_offset_t byte) →  byte_offset_t noexcept
Byte offset of the nearest grapheme boundary at or before byte.
auto grapheme_index(std::size_t n) →  grapheme_index_t constexpr noexcept
Construct a grapheme index.
auto is_line_break(std::string_view cluster) →  bool noexcept
True when a grapheme cluster is a line break.
auto is_word_separator(std::string_view cluster) →  bool noexcept
True when a grapheme cluster should separate words.
auto next(std::string_view text, byte_offset_t byte) →  byte_offset_t noexcept
auto operator-(byte_offset_t a, byte_offset_t b) →  std::size_t constexpr noexcept
Difference between two byte offsets.
auto prev(std::string_view text, byte_offset_t byte) →  byte_offset_t noexcept
auto segments(std::string_view text) →  segment_view noexcept
Return a segment range over borrowed text.
auto words(std::string_view text) →  word_view noexcept
Return a word range over borrowed text.

Function documentation

byte_offset_t nxt::utf8::byte_at(std::string_view text, grapheme_index_t cell) noexcept

Byte offset at the cell-th grapheme cluster (clamped to text.size()).

byte_offset_t nxt::utf8::byte_at_column(std::string_view text, width_t column) noexcept

Byte offset for the grapheme cluster at column.

byte_offset_t nxt::utf8::byte_offset(std::size_t n) constexpr noexcept

Construct a byte offset.

grapheme_index_t nxt::utf8::cell_at(std::string_view text, byte_offset_t byte) noexcept

Grapheme cluster index for a byte offset, snapped to the previous boundary.

width_t nxt::utf8::cluster_width(std::string_view cluster) noexcept

Display width of one grapheme cluster.

width_t nxt::utf8::column_at(std::string_view text, byte_offset_t byte) noexcept

Display column for a byte offset, snapped to the previous boundary.

std::size_t nxt::utf8::complete_words_prefix_size(std::string_view text) noexcept

Size in bytes of the prefix that ends on a word boundary.

grapheme_index_t nxt::utf8::count(std::string_view text) noexcept

Number of grapheme clusters in text.

width_t nxt::utf8::display_width(std::string_view text) noexcept

Display width of all grapheme clusters in text.

byte_offset_t nxt::utf8::floor_boundary(std::string_view text, byte_offset_t byte) noexcept

Byte offset of the nearest grapheme boundary at or before byte.

grapheme_index_t nxt::utf8::grapheme_index(std::size_t n) constexpr noexcept

Construct a grapheme index.

bool nxt::utf8::is_line_break(std::string_view cluster) noexcept

True when a grapheme cluster is a line break.

bool nxt::utf8::is_word_separator(std::string_view cluster) noexcept

True when a grapheme cluster should separate words.

byte_offset_t nxt::utf8::next(std::string_view text, byte_offset_t byte) noexcept

Byte offset of the grapheme cluster after the one starting at byte. Returns text.size() if byte is at or past the end.

std::size_t nxt::utf8::operator-(byte_offset_t a, byte_offset_t b) constexpr noexcept

Difference between two byte offsets.

byte_offset_t nxt::utf8::prev(std::string_view text, byte_offset_t byte) noexcept

Byte offset of the grapheme cluster before the one ending at byte. Returns 0 if byte is at the start.

segment_view nxt::utf8::segments(std::string_view text) noexcept

Return a segment range over borrowed text.

word_view nxt::utf8::words(std::string_view text) noexcept

Return a word range over borrowed text.