HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Friends
v1::grapheme Struct Reference

#include <hikogui/unicode/grapheme.hpp>

Public Types

using value_type = uint32_t
 

Public Member Functions

constexpr grapheme (grapheme const &) noexcept=default
 
constexpr grapheme (grapheme &&) noexcept=default
 
constexpr graphemeoperator= (grapheme const &) noexcept=default
 
constexpr graphemeoperator= (grapheme &&) noexcept=default
 
constexpr grapheme (nullptr_t) noexcept
 
constexpr grapheme (char32_t code_point) noexcept
 Encode a single code-point.
 
constexpr grapheme (char ascii_char) noexcept
 
constexpr graphemeoperator= (char32_t code_point) noexcept
 Encode a single code-point.
 
constexpr graphemeoperator= (char ascii_char) noexcept
 Encode a single code-point.
 
 grapheme (std::u32string_view code_points) noexcept
 Encode a grapheme from a list of code-points.
 
 grapheme (composed_t, std::u32string_view code_points) noexcept
 Encode a grapheme from a list of code-points.
 
constexpr void clear () noexcept
 Clear the grapheme.
 
constexpr bool empty () const noexcept
 Check if the grapheme is empty.
 
constexpr operator bool () const noexcept
 Check if the grapheme holds any code-points.
 
bool valid () const noexcept
 Check if the grapheme is valid.
 
std::u32string const & long_grapheme () const noexcept
 
constexpr std::size_t size () const noexcept
 Return the number of code-points encoded in the grapheme.
 
constexpr char32_t operator[] (size_t i) const noexcept
 Get the code-point at the given index.
 
constexpr std::u32string composed () const noexcept
 Get a list of code-point normalized to NFC.
 
std::u32string decomposed () const noexcept
 Get a list of code-point normalized to NFD.
 

Static Public Member Functions

static constexpr grapheme eof () noexcept
 Create empty grapheme / end-of-file.
 

Data Fields

value_type _value
 A pointer to a grapheme.
 

Friends

template<size_t I>
constexpr char32_t get (grapheme const &rhs) noexcept
 Get the code-point at the given index.
 
constexpr bool operator== (grapheme const &, grapheme const &) noexcept=default
 Compare equivalence of two graphemes.
 
constexpr std::strong_ordering operator<=> (grapheme const &lhs, grapheme const &rhs) noexcept
 Compare two graphemes lexicographically.
 
constexpr bool operator== (grapheme const &lhs, char32_t const &rhs) noexcept
 
constexpr std::strong_ordering operator<=> (grapheme const &lhs, char32_t const &rhs) noexcept
 
constexpr bool operator== (grapheme const &lhs, char const &rhs) noexcept
 
constexpr std::strong_ordering operator<=> (grapheme const &lhs, char const &rhs) noexcept
 
std::string to_string (grapheme const &rhs) noexcept
 
std::u32string to_u32string (grapheme const &rhs) noexcept
 

Detailed Description

A grapheme-cluster, what a user thinks a character is.

A grapheme should not include typographical ligatures such as 'fi' as the font should handle creating ligatures.

If a grapheme is initialized with more than 1 code-points a long_grapheme is allocated. This grapheme is never deleted from memory.

This class is trivial and constant-destructible so that it can be used as a character class in std::basic_string and used as a non-type template parameter.

Constructor & Destructor Documentation

◆ grapheme() [1/3]

constexpr v1::grapheme::grapheme ( char32_t code_point)
inlineexplicitconstexprnoexcept

Encode a single code-point.

◆ grapheme() [2/3]

v1::grapheme::grapheme ( std::u32string_view code_points)
explicitnoexcept

Encode a grapheme from a list of code-points.

Parameters
code_pointsThe non-normalized list of code-points.

◆ grapheme() [3/3]

v1::grapheme::grapheme ( composed_t ,
std::u32string_view code_points )
explicitnoexcept

Encode a grapheme from a list of code-points.

Parameters
code_pointsThe NFC/NKFC normalized and composed code-point of this grapheme.

Member Function Documentation

◆ clear()

constexpr void v1::grapheme::clear ( )
inlineconstexprnoexcept

Clear the grapheme.

◆ composed()

constexpr std::u32string v1::grapheme::composed ( ) const
inlineconstexprnoexcept

Get a list of code-point normalized to NFC.

◆ decomposed()

std::u32string v1::grapheme::decomposed ( ) const
noexcept

Get a list of code-point normalized to NFD.

◆ empty()

constexpr bool v1::grapheme::empty ( ) const
inlineconstexprnoexcept

Check if the grapheme is empty.

◆ eof()

static constexpr grapheme v1::grapheme::eof ( )
inlinestaticconstexprnoexcept

Create empty grapheme / end-of-file.

◆ operator bool()

constexpr v1::grapheme::operator bool ( ) const
inlineconstexprnoexcept

Check if the grapheme holds any code-points.

◆ operator=() [1/2]

constexpr grapheme & v1::grapheme::operator= ( char ascii_char)
inlineconstexprnoexcept

Encode a single code-point.

◆ operator=() [2/2]

constexpr grapheme & v1::grapheme::operator= ( char32_t code_point)
inlineconstexprnoexcept

Encode a single code-point.

◆ operator[]()

constexpr char32_t v1::grapheme::operator[] ( size_t i) const
inlineconstexprnoexcept

Get the code-point at the given index.

Note
It is undefined-behavior to index beyond the number of encoded code-points.
Parameters
iIndex of code-point in the grapheme.
Returns
code-point at the given index.

◆ size()

constexpr std::size_t v1::grapheme::size ( ) const
inlineconstexprnoexcept

Return the number of code-points encoded in the grapheme.

◆ valid()

bool v1::grapheme::valid ( ) const
noexcept

Check if the grapheme is valid.

A grapheme is invalid in case:

  • The grapheme is empty.
  • The first code-point is part of general category 'C'.
  • The first code-point is a combining character; canonical combining class != 0.

Friends And Related Symbol Documentation

◆ get

template<size_t I>
constexpr char32_t get ( grapheme const & rhs)
friend

Get the code-point at the given index.

Note
It is undefined-behavior to index beyond the number of encoded code-points.
Template Parameters
IIndex of code-point in the grapheme.
Parameters
rhsThe grapheme to query.
Returns
code-point at the given index.

◆ operator<=>

constexpr std::strong_ordering operator<=> ( grapheme const & lhs,
grapheme const & rhs )
friend

Compare two graphemes lexicographically.

◆ operator==

constexpr bool operator== ( grapheme const & ,
grapheme const &  )
friend

Compare equivalence of two graphemes.

Field Documentation

◆ _value

value_type v1::grapheme::_value

A pointer to a grapheme.

This class will hold:

  • A single code point between U+0000 to U+10ffff, or
  • An index + 0x110000 into the long_graphemes table, or
  • 0x1fffff meaning empty/eof.

Bits [31:21] are always '0'.


The documentation for this struct was generated from the following file: