Overview / Text & language

text

Everything that requires knowing what each character is in Unicode 18.0.0: properties, normalization, case, segmentation, line breaking, width, collation, IDNA and bidi. Tables are generated from the UCD, and no path uses dynamic memory.

Always compiled: part of the core build.Include #include <ethereal/cpp/text/text_inc.hpp>C layer

text_inc.hpp

#include <ethereal/cpp/text/text_inc.hpp>

Aggregate entry point of the Text module.

Everything that needs to know what characters mean: properties, normalization, case, collation, segmentation, line breaking, bidi and IDN, with the Unicode 18 tables generated from the UCD.

text_bidi.hpp

#include <ethereal/cpp/text/text_bidi.hpp>

Bidirectional text (UAX 9).

The whole algorithm up to L2: the paragraph direction (P2, P3), the explicit levels with the isolates (X1-X10), the weak types (W1-W7), the paired brackets (N0), the neutrals (N1, N2), the implicit levels (I1, I2), L1 and the reordering (L2). L3 (combining marks) belongs to rendering. L4 is MirroredGlyph.

No dynamic memory: the caller provides the space, one level per code point and the work area (BidiWorkSize). Code points are those of the text read forward, and each subpart of invalid UTF-8 is one (CountCodePoints).

Several paragraphs: each paragraph separator (class B) closes one (P1), and each has its own direction. One line: L1 treats the paragraph as a single line. For wrapped text, BidiLineEnd applies the end of each line to its levels, and BidiReorder reorders it.

enum

EBidiDirection

Ethereal::Text#
C++
enum class   EBidiDirection : std::uint8_t
{
    /// @brief  Left to right.
    eLTR = 0,

    /// @brief  Right to left.
    eRTL = 1,

    /// @brief  From the first strong character (P2, P3). LTR when there is none.
    eAuto = 2,
};

Paragraph direction.

const

kBidiRemoved

Ethereal::Text#
inline constexpr std::uint8_t kBidiRemoved = 0xFF;

Level of the code points that X9 removes (the embedding marks, BN). They are not drawn, and BidiReorder skips them.

function

BidiWorkSize

Ethereal::Text#
constexpr std::size_t BidiWorkSize( const std::size_t nCodePoints ) noexcept

Work area size, in bytes, for nCodePoints. Enough for every function.

function

BidiLevels

Ethereal::Text#
ETextStatus BidiLevels( std::string_view s, EBidiDirection eDirection, std::span< std::uint8_t > Levels, std::span< std::uint8_t > Work, std::uint8_t * pParagraphLevel = nullptr ) noexcept;

Level of each code point, up to L1, with the paragraph as one line.

s
The text.
eDirection
Paragraph direction.
Levels
One per code point. kBidiRemoved on the ones X9 removes.
Work
At least BidiWorkSize( CountCodePoints( s ) ) bytes.
pParagraphLevel
Receives the level of the first paragraph (0 LTR, 1 RTL). May be null.
eOk, eBufferTooSmall (Levels or Work too small) or eInvalidArgument.
function

BidiLineEnd

Ethereal::Text#
void BidiLineEnd( std::string_view sLine, std::span< std::uint8_t > Levels, std::uint8_t uParagraphLevel ) noexcept;

L1 at the end of a line: trailing spaces and isolates go back to the paragraph level.

sLine
The line only.
Levels
Levels of the line only.
uParagraphLevel
Paragraph level.
function

BidiReorder

Ethereal::Text#
ETextStatus BidiReorder( std::span< const std::uint8_t > Levels, std::span< std::uint32_t > VisualOrder, std::size_t * pCount ) noexcept;

L2: the visual order (left to right) of the code points of a line, as indices.

The kBidiRemoved code points are left out.

Levels
Levels of the line.
VisualOrder
Receives the indices.
pCount
Receives how many indices.
eOk, eBufferTooSmall or eInvalidArgument.
function

MirroredGlyph

Ethereal::Text#
char32_t MirroredGlyph( char32_t cp ) noexcept;

Mirror of cp for right to left rendering (L4), or cp itself when it has none ("(" <-> ")", "<" <-> ">").

function

BidiToVisual

Ethereal::Text#
ETextStatus BidiToVisual( std::string_view sLine, EBidiDirection eDirection, std::span< char > Out, std::size_t * pWritten, std::span< std::uint8_t > Work ) noexcept;

A line in visual order and with the mirrors (UTF-8), without the X9 code points.

sLine
The line.
eDirection
Paragraph direction.
Out
Receives the result.
pWritten
Receives the size needed.
Work
At least BidiWorkSize( CountCodePoints( sLine ) ) bytes.
eOk, eBufferTooSmall or eInvalidArgument.

text_case.hpp

#include <ethereal/cpp/text/text_case.hpp>

Case: uppercase, lowercase, titlecase and folding.

The full mapping, not the simple one. 'ß' in uppercase is "SS", the ligature 'fi' is "FI", 'ʼn' is "ʼN". A library that only does the simple mapping gives wrong results, and the reports come precisely from the people who care. Text may grow: up to 3 code points per code point.

Folding is not lowercasing. Folding (CaseFold) is for comparing. It gives different results ('ß' folds to "ss", the final sigma folds to 'σ') and is what to use to know whether two strings are equal ignoring case. 'ToLower(a) == ToLower(b)' is the wrong way, and the Turkish 'I' is the classic example.

Language exceptions are opt in and off by default: Turkish and Azeri ('I' to 'ı', 'İ' to 'i') and Lithuanian (the dot above 'i' before accents). The Greek final sigma always applies (it comes from the standard, not from a language).

The comparison does not do canonical equivalence. "é" (one code point) and "e" + U+0301 differ for CaseInsensitiveEquals. Normalize both to NFC first if the data mixes the forms.

enum

ECaseLocale

Ethereal::Text#
C++
enum class   ECaseLocale : std::uint8_t
{
    /// @brief  No language exceptions.
    eDefault = 0,

    /// @brief  tr, az.
    eTurkic,

    /// @brief  lt.
    eLithuanian,
};

Language rules applied by the case functions.

function

ToLower

Ethereal::Text#
ETextStatus ToLower( std::string_view sIn, std::span< char > Out, std::size_t * pWritten, ECaseLocale eLocale = ECaseLocale::eDefault ) noexcept;

Full lowercase mapping. Rejects invalid UTF-8.

sIn
The text.
Out
Receives the result.
pWritten
Receives the size needed.
eLocale
Language rules.
eOk, eBufferTooSmall, eInvalidUtf8 or eInvalidArgument.
function

ToUpper

Ethereal::Text#
ETextStatus ToUpper( std::string_view sIn, std::span< char > Out, std::size_t * pWritten, ECaseLocale eLocale = ECaseLocale::eDefault ) noexcept;

Full uppercase mapping. Rejects invalid UTF-8.

sIn
The text.
Out
Receives the result.
pWritten
Receives the size needed.
eLocale
Language rules.
eOk, eBufferTooSmall, eInvalidUtf8 or eInvalidArgument.
function

ToTitle

Ethereal::Text#
ETextStatus ToTitle( std::string_view sIn, std::span< char > Out, std::size_t * pWritten, ECaseLocale eLocale = ECaseLocale::eDefault ) noexcept;

Titlecase by word.

The first cased character of each word (the UAX 29 words) goes to titlecase, the following ones to lowercase, and the ones before it stay as they are. This is the Unicode R3 definition, to the letter: "3rd" gives "3Rd". Needs segmentation (eNotSupported without it).

sIn
The text.
Out
Receives the result.
pWritten
Receives the size needed.
eLocale
Language rules.
eOk, eBufferTooSmall, eInvalidUtf8, eInvalidArgument or eNotSupported.
function

CaseFold

Ethereal::Text#
ETextStatus CaseFold( std::string_view sIn, std::span< char > Out, std::size_t * pWritten, ECaseLocale eLocale = ECaseLocale::eDefault ) noexcept;

Full case folding (C+F of CaseFolding.txt, and with eTurkic also the T ones).

sIn
The text.
Out
Receives the result.
pWritten
Receives the size needed.
eLocale
Language rules.
eOk, eBufferTooSmall, eInvalidUtf8 or eInvalidArgument.
function

CaseInsensitiveEquals

Ethereal::Text#
bool CaseInsensitiveEquals( std::string_view a, std::string_view b, ECaseLocale eLocale = ECaseLocale::eDefault ) noexcept;

Equal ignoring case.

Folds both sides as it goes, allocating nothing. ASCII (almost every call) is resolved without tables. Invalid UTF-8 reads as U+FFFD.

a
First text.
b
Second text.
eLocale
Language rules.
true when the folded texts are equal.
function

SimpleLower

Ethereal::Text#
char32_t SimpleLower( char32_t cp ) noexcept;

Simple lowercase mapping, one code point to one (UnicodeData).

For code that needs 1:1, such as a Regex character class.

function

SimpleUpper

Ethereal::Text#
char32_t SimpleUpper( char32_t cp ) noexcept;

Simple uppercase mapping, one code point to one (UnicodeData).

function

SimpleTitle

Ethereal::Text#
char32_t SimpleTitle( char32_t cp ) noexcept;

Simple titlecase mapping, one code point to one (UnicodeData).

function

SimpleFold

Ethereal::Text#
char32_t SimpleFold( char32_t cp ) noexcept;

Simple case folding, one code point to one (S and C of CaseFolding.txt).

function

SimpleCaseOrbitNext

Ethereal::Text#
char32_t SimpleCaseOrbitNext( char32_t cp ) noexcept;

Next code point in the simple case orbit of cp.

The orbit is the code points with the same simple folding, in increasing order, in a cycle ('K' -> 'k' -> U+212A -> 'K'). Following it back to the start gives every case of a code point, which is what '(?i)' in a regular expression matches.

cp
The code point.
The next code point, or cp when it has no others.
function

LowerFull

Ethereal::Text#
std::size_t LowerFull( char32_t cp, char32_t ( &aOut )[ 3 ] ) noexcept;

Full lowercase mapping of one code point, without context.

The unconditional mappings of SpecialCasing.txt, and the simple mapping of UnicodeData.txt for the rest. No Final_Sigma and no language rule: U+03A3 always gives U+03C3, U+0130 gives "i" followed by U+0307. This is the per character mapping of Rust's char::to_lowercase, which the Lowercase normalizer of the Hugging Face tokenizers applies. ToLower is the mapping of a text, with the context rules.

cp
The code point. Outside the Unicode range it maps to itself.
aOut
Receives the mapping.
The number of code points written, 1 to 3.

text_collation.hpp

#include <ethereal/cpp/text/text_collation.hpp>

Collation (UTS 10): sorting text the way people expect.

The Unicode Collation Algorithm with the default table (DUCET), the "root" order: the same for every language, and the one CLDR uses as its base. Provides the levels (primary: letters, secondary: accents, tertiary: case and variants, quaternary: ignored punctuation, identical: tie break by code point), ignored variables (eShifted), backwards accents (French), the case level, and numbers by value (bNumeric: "2" before "10").

Not provided: the order of each CLDR language. That is megabytes of data and years of upkeep. Instead there is a small format of tailorings that the user writes for a language (CCollationTailoring): "X comes right after Y, at this level". It is enough for the Spanish ñ, the Czech ch, the Danish å. It has no "before", no script reordering and none of the dozens of CLDR options.

The sort key compares with memcmp and always agrees with Compare: compute it once per text and sort a large list with memcmp only. The format is the standard one: the weights of each level (16 bits, big-endian), levels separated by 0000. The identical level holds the NFD code points (3 bytes each).

The text goes through NFD (collation requires it). A run of more than 30 combining marks is handled as in the "Stream-Safe Text Format" of UAX 15 (as if there were a CGJ every 30). That keeps everything free of dynamic memory and only changes text no language writes. Invalid UTF-8: each subpart is a U+FFFD, which sorts last.

enum

ECollationStrength

Ethereal::Text#
C++
enum class   ECollationStrength : std::uint8_t
{
    /// @brief  Letters only: "a" = "A" = "á".
    ePrimary = 1,

    /// @brief  And accents: "a" = "A" < "á".
    eSecondary,

    /// @brief  And case and variants: "a" < "A" < "á". The default.
    eTertiary,

    /// @brief  And, with eShifted, the punctuation the other levels ignored.
    eQuaternary,

    /// @brief  And, at the end, the code points.
    eIdentical,
};

How many levels the comparison looks at.

enum

ECollationAlternate

Ethereal::Text#
C++
enum class   ECollationAlternate : std::uint8_t
{
    /// @brief  Spaces and punctuation count as letters. The default, and the CLDR one.
    eNonIgnorable = 0,

    /// @brief  Ignored on levels 1 to 3 ("de luge" = "deluge"), weighted only on level 4.
    eShifted,
};

How variables (spaces and punctuation) are weighted.

struct

SCollationRule

Ethereal::Text#
C++
struct   SCollationRule
{
    /// @brief  The existing text the item goes after (Y).
    std::string_view        sAnchor;

    /// @brief  The tailored text (X).
    std::string_view        sItem;

    /// @brief  Level of the difference: ePrimary, eSecondary or eTertiary.
    ECollationStrength        eLevel = ECollationStrength::ePrimary;
};

One tailoring: sItem comes right after sAnchor at level eLevel (primary, secondary or tertiary).

Like the CLDR "&Y < X", "&Y << X" and "&Y <<< X". The item goes after Y and after everything that starts like Y ("nz" < "ñ"), and before what already differs from Y at that level (q tailored after o stays before O). Several tailorings to the same anchor keep the order of the rules.

C++
//    Spanish: ñ is a letter between n and o. Ñ is its uppercase.
const SCollationRule aEs[] = { { "n", "\xC3\xB1", ECollationStrength::ePrimary },
                               { "\xC3\xB1", "\xC3\x91", ECollationStrength::eTertiary } };
//    Czech: ch is a letter, after h.
const SCollationRule aCs[] = { { "h", "ch", ECollationStrength::ePrimary } };
class

CCollationTailoring

Ethereal::Text#

A set of tailorings, built once and used in any number of comparisons.

class CCollationTailoring

No dynamic memory: the capacity is fixed.

const

kMaxRules

#
static constexpr std::size_t kMaxRules = 64;

Maximum number of rules.

const

kMaxItem

#
static constexpr std::size_t kMaxItem = 8;

Maximum code points of an item, in NFD.

const

kMaxCEs

#
static constexpr std::size_t kMaxCEs = 16;

Maximum collation elements of a tailored item.

function

Build

#
ETextStatus Build( std::span< const SCollationRule > Rules ) noexcept;

Compiles the rules, in order. Each anchor may use the previous tailorings.

Rules
The rules.
eOk, or eInvalidArgument for more than kMaxRules, an empty, long or invalid UTF-8 item, an empty anchor or one with too many elements, or a level that is not 1 to 3. eNotLicensed when the library is not licensed. On error the set is left empty.
function

Count

#
std::size_t Count() const noexcept

Number of compiled rules.

struct

SRule

#
C++
struct   SRule
{
    /// @brief  The item, in NFD.
    char32_t        aItem[ kMaxItem ];

    /// @brief  Primary, secondary and tertiary weights of each element.
    std::uint16_t    aP[ kMaxCEs ], aS[ kMaxCEs ], aT[ kMaxCEs ];

    /// @brief  Code points in aItem.
    std::uint8_t    nItem;

    /// @brief  Elements in aP, aS and aT.
    std::uint8_t    nCE;
};

(Internal) A compiled rule.

function

Rule

#
const SRule & Rule( const std::size_t i ) const noexcept

(Internal) Compiled rule i.

struct

SCollationOptions

Ethereal::Text#
C++
struct   SCollationOptions
{
    /// @brief  Levels compared.
    ECollationStrength            eStrength = ECollationStrength::eTertiary;

    /// @brief  How variables are weighted.
    ECollationAlternate            eAlternate = ECollationAlternate::eNonIgnorable;

    /// @brief  Accents from the end to the start (French).
    bool                        bBackwardSecondary = false;

    /// @brief  A level only for case, after the accents.
    bool                        bCaseLevel = false;

    /// @brief  Numbers by value ("2" < "10").
    bool                        bNumeric = false;

    /// @brief  Tailorings to apply. May be null.
    const CCollationTailoring *    pTailoring = nullptr;
};

Collation options.

function

SortKey

Ethereal::Text#
ETextStatus SortKey( std::string_view s, std::span< std::uint8_t > Out, std::size_t * pWritten, const SCollationOptions & Options = {} ) noexcept;

Sort key of a text.

s
The text.
Out
Receives the key.
pWritten
Receives the size needed, also with eBufferTooSmall.
Options
Collation options.
eOk, eBufferTooSmall, or eInvalidArgument with options outside the enumerations.
function

Compare

Ethereal::Text#
int Compare( std::string_view a, std::string_view b, const SCollationOptions & Options = {} ) noexcept;

Compares two texts like memcmp of their sort keys.

Does not compute the whole keys and uses no dynamic memory.

a
First text.
b
Second text.
Options
Collation options.
Negative, zero or positive.

text_common.hpp

#include <ethereal/cpp/text/text_common.hpp>

Shared types and conventions of the Text module.

Text is UTF-8 in std::string_view. The functions that write take the destination as std::span< char > and report in *pWritten how many bytes they wrote or, with eBufferTooSmall, how many would be needed (the destination is left with partial garbage). Nothing writes a terminating zero. No function that writes into a span allocates memory.

Invalid UTF-8: the functions that transform (normalize, change case) reject it with eInvalidUtf8, because transforming broken text silently hides the damage. The ones that compare or measure read each invalid sequence as U+FFFD (the maximal subpart, as Unicode recommends), so they never stop halfway.

enum

ETextStatus

Ethereal::Text#
C++
enum class   ETextStatus : std::uint8_t
{
    /// @brief  Success.
    eOk = 0,

    /// @brief  An argument has no usable value.
    eInvalidArgument,

    /// @brief  The destination is too small. *pWritten tells how much was needed.
    eBufferTooSmall,

    /// @brief  The input is not valid UTF-8.
    eInvalidUtf8,

    /// @brief  CNormalizer got a combining sequence larger than its buffer.
    eSegmentTooLong,

    /// @brief  The capability was disabled at build time.
    eNotSupported,

    /// @brief  IDNA: the domain is not valid (the IdnaError codes tell why).
    eDomainInvalid,

    /// @brief  Refused: no license was accepted and the evaluation of this machine has
    ///             ended, or the license passed was refused (see Bundle::UnlockBundle).
    eNotLicensed,
};

Result of a Text function.

function

StatusName

Ethereal::Text#
const char * StatusName( ETextStatus e ) noexcept;

Readable name of an ETextStatus.

e
The status.
Static null terminated string. Never null.
function

CountCodePoints

Ethereal::Text#
std::size_t CountCodePoints( std::string_view s ) noexcept;

Number of code points in the text.

Each subpart of invalid UTF-8 counts as one, as U+FFFD. This is the same reading the whole module uses.

s
The text.
Number of code points.

text_enums.hpp

#include <ethereal/cpp/text/text_enums.hpp>

Enumerations of the Unicode properties used by the Text module.

Generated by 'tools/unicode_gen/gen_text.py' from Unicode 18.0.0. Do not edit: change the generator and run it again.

const

kUnicodeMajor

Ethereal::Text#
inline constexpr std::uint8_t kUnicodeMajor = 18, kUnicodeMinor = 0, kUnicodeUpdate = 0;

Unicode version of the tables.

enum

EGeneralCategory

Ethereal::Text#
C++
enum class   EGeneralCategory : std::uint8_t
{
    eControl = 0,        ///< Cc
    eFormat = 1,        ///< Cf
    eUnassigned = 2,        ///< Cn
    ePrivateUse = 3,        ///< Co
    eSurrogate = 4,        ///< Cs
    eLowercaseLetter = 5,        ///< Ll
    eModifierLetter = 6,        ///< Lm
    eOtherLetter = 7,        ///< Lo
    eTitlecaseLetter = 8,        ///< Lt
    eUppercaseLetter = 9,        ///< Lu
    eSpacingMark = 10,        ///< Mc
    eEnclosingMark = 11,        ///< Me
    eNonspacingMark = 12,        ///< Mn
    eDecimalNumber = 13,        ///< Nd
    eLetterNumber = 14,        ///< Nl
    eOtherNumber = 15,        ///< No
    eConnectorPunctuation = 16,        ///< Pc
    eDashPunctuation = 17,        ///< Pd
    eClosePunctuation = 18,        ///< Pe
    eFinalPunctuation = 19,        ///< Pf
    eInitialPunctuation = 20,        ///< Pi
    eOtherPunctuation = 21,        ///< Po
    eOpenPunctuation = 22,        ///< Ps
    eCurrencySymbol = 23,        ///< Sc
    eModifierSymbol = 24,        ///< Sk
    eMathSymbol = 25,        ///< Sm
    eOtherSymbol = 26,        ///< So
    eLineSeparator = 27,        ///< Zl
    eParagraphSeparator = 28,        ///< Zp
    eSpaceSeparator = 29,        ///< Zs
    kCount = 30
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

EBidiClass

Ethereal::Text#
C++
enum class   EBidiClass : std::uint8_t
{
    eArabicLetter = 0,        ///< AL
    eArabicNumber = 1,        ///< AN
    eParagraphSeparator = 2,        ///< B
    eBoundaryNeutral = 3,        ///< BN
    eCommonSeparator = 4,        ///< CS
    eEuropeanNumber = 5,        ///< EN
    eEuropeanSeparator = 6,        ///< ES
    eEuropeanTerminator = 7,        ///< ET
    eFirstStrongIsolate = 8,        ///< FSI
    eLeftToRight = 9,        ///< L
    eLeftToRightEmbedding = 10,        ///< LRE
    eLeftToRightIsolate = 11,        ///< LRI
    eLeftToRightOverride = 12,        ///< LRO
    eNonspacingMark = 13,        ///< NSM
    eOtherNeutral = 14,        ///< ON
    ePopDirectionalFormat = 15,        ///< PDF
    ePopDirectionalIsolate = 16,        ///< PDI
    eRightToLeft = 17,        ///< R
    eRightToLeftEmbedding = 18,        ///< RLE
    eRightToLeftIsolate = 19,        ///< RLI
    eRightToLeftOverride = 20,        ///< RLO
    eSegmentSeparator = 21,        ///< S
    eWhiteSpace = 22,        ///< WS
    kCount = 23
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

ELineBreak

Ethereal::Text#
C++
enum class   ELineBreak : std::uint8_t
{
    eAmbiguous = 0,        ///< AI
    eAksara = 1,        ///< AK
    eAlphabetic = 2,        ///< AL
    eAksaraPrebase = 3,        ///< AP
    eAksaraStart = 4,        ///< AS
    eBreakBoth = 5,        ///< B2
    eBreakAfter = 6,        ///< BA
    eBreakBefore = 7,        ///< BB
    eMandatoryBreak = 8,        ///< BK
    eContingentBreak = 9,        ///< CB
    eConditionalJapaneseStarter = 10,        ///< CJ
    eClosePunctuation = 11,        ///< CL
    eCombiningMark = 12,        ///< CM
    eCloseParenthesis = 13,        ///< CP
    eCarriageReturn = 14,        ///< CR
    eEBase = 15,        ///< EB
    eEModifier = 16,        ///< EM
    eExclamation = 17,        ///< EX
    eGlue = 18,        ///< GL
    eH2 = 19,        ///< H2
    eH3 = 20,        ///< H3
    eUnambiguousHyphen = 21,        ///< HH
    eHebrewLetter = 22,        ///< HL
    eHyphen = 23,        ///< HY
    eIdeographic = 24,        ///< ID
    eInseparable = 25,        ///< IN
    eInfixNumeric = 26,        ///< IS
    eJL = 27,        ///< JL
    eJT = 28,        ///< JT
    eJV = 29,        ///< JV
    eLineFeed = 30,        ///< LF
    eNextLine = 31,        ///< NL
    eNonstarter = 32,        ///< NS
    eNumeric = 33,        ///< NU
    eOpenPunctuation = 34,        ///< OP
    ePostfixNumeric = 35,        ///< PO
    ePrefixNumeric = 36,        ///< PR
    eQuotation = 37,        ///< QU
    eRegionalIndicator = 38,        ///< RI
    eComplexContext = 39,        ///< SA
    eSurrogate = 40,        ///< SG
    eSpace = 41,        ///< SP
    eBreakSymbols = 42,        ///< SY
    eViramaFinal = 43,        ///< VF
    eVirama = 44,        ///< VI
    eWordJoiner = 45,        ///< WJ
    eUnknown = 46,        ///< XX
    eZWSpace = 47,        ///< ZW
    eZWJ = 48,        ///< ZWJ
    kCount = 49
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

EEastAsianWidth

Ethereal::Text#
C++
enum class   EEastAsianWidth : std::uint8_t
{
    eAmbiguous = 0,        ///< A
    eFullwidth = 1,        ///< F
    eHalfwidth = 2,        ///< H
    eNeutral = 3,        ///< N
    eNarrow = 4,        ///< Na
    eWide = 5,        ///< W
    kCount = 6
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

EGraphemeBreak

Ethereal::Text#
C++
enum class   EGraphemeBreak : std::uint8_t
{
    eControl = 0,        ///< CN
    eCR = 1,        ///< CR
    eEBase = 2,        ///< EB
    eEBaseGAZ = 3,        ///< EBG
    eEModifier = 4,        ///< EM
    eExtend = 5,        ///< EX
    eGlueAfterZwj = 6,        ///< GAZ
    eL = 7,        ///< L
    eLF = 8,        ///< LF
    eLV = 9,        ///< LV
    eLVT = 10,        ///< LVT
    ePrepend = 11,        ///< PP
    eRegionalIndicator = 12,        ///< RI
    eSpacingMark = 13,        ///< SM
    eT = 14,        ///< T
    eV = 15,        ///< V
    eOther = 16,        ///< XX
    eZWJ = 17,        ///< ZWJ
    kCount = 18
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

EWordBreak

Ethereal::Text#
C++
enum class   EWordBreak : std::uint8_t
{
    eCR = 0,        ///< CR
    eDoubleQuote = 1,        ///< DQ
    eEBase = 2,        ///< EB
    eEBaseGAZ = 3,        ///< EBG
    eEModifier = 4,        ///< EM
    eExtendNumLet = 5,        ///< EX
    eExtend = 6,        ///< Extend
    eFormat = 7,        ///< FO
    eGlueAfterZwj = 8,        ///< GAZ
    eHebrewLetter = 9,        ///< HL
    eKatakana = 10,        ///< KA
    eALetter = 11,        ///< LE
    eLF = 12,        ///< LF
    eMidNumLet = 13,        ///< MB
    eMidLetter = 14,        ///< ML
    eMidNum = 15,        ///< MN
    eNewline = 16,        ///< NL
    eNumeric = 17,        ///< NU
    eRegionalIndicator = 18,        ///< RI
    eSingleQuote = 19,        ///< SQ
    eWSegSpace = 20,        ///< WSegSpace
    eOther = 21,        ///< XX
    eZWJ = 22,        ///< ZWJ
    kCount = 23
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

ESentenceBreak

Ethereal::Text#
C++
enum class   ESentenceBreak : std::uint8_t
{
    eATerm = 0,        ///< AT
    eClose = 1,        ///< CL
    eCR = 2,        ///< CR
    eExtend = 3,        ///< EX
    eFormat = 4,        ///< FO
    eOLetter = 5,        ///< LE
    eLF = 6,        ///< LF
    eLower = 7,        ///< LO
    eNumeric = 8,        ///< NU
    eSContinue = 9,        ///< SC
    eSep = 10,        ///< SE
    eSp = 11,        ///< SP
    eSTerm = 12,        ///< ST
    eUpper = 13,        ///< UP
    eOther = 14,        ///< XX
    kCount = 15
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

EScript

Ethereal::Text#
C++
enum class   EScript : std::uint8_t
{
    eAdlam = 0,        ///< Adlm
    eCaucasianAlbanian = 1,        ///< Aghb
    eAhom = 2,        ///< Ahom
    eArabic = 3,        ///< Arab
    eImperialAramaic = 4,        ///< Armi
    eArmenian = 5,        ///< Armn
    eAvestan = 6,        ///< Avst
    eBalinese = 7,        ///< Bali
    eBamum = 8,        ///< Bamu
    eBassaVah = 9,        ///< Bass
    eBatak = 10,        ///< Batk
    eBengali = 11,        ///< Beng
    eBeriaErfe = 12,        ///< Berf
    eBhaiksuki = 13,        ///< Bhks
    eBopomofo = 14,        ///< Bopo
    eBrahmi = 15,        ///< Brah
    eBraille = 16,        ///< Brai
    eBuginese = 17,        ///< Bugi
    eBuhid = 18,        ///< Buhd
    eChakma = 19,        ///< Cakm
    eCanadianAboriginal = 20,        ///< Cans
    eCarian = 21,        ///< Cari
    eCham = 22,        ///< Cham
    eCherokee = 23,        ///< Cher
    eChorasmian = 24,        ///< Chrs
    eCoptic = 25,        ///< Copt
    eCyproMinoan = 26,        ///< Cpmn
    eCypriot = 27,        ///< Cprt
    eCyrillic = 28,        ///< Cyrl
    eDevanagari = 29,        ///< Deva
    eDivesAkuru = 30,        ///< Diak
    eDogra = 31,        ///< Dogr
    eDeseret = 32,        ///< Dsrt
    eDuployan = 33,        ///< Dupl
    eEgyptianHieroglyphs = 34,        ///< Egyp
    eElbasan = 35,        ///< Elba
    eElymaic = 36,        ///< Elym
    eEthiopic = 37,        ///< Ethi
    eGaray = 38,        ///< Gara
    eGeorgian = 39,        ///< Geor
    eGlagolitic = 40,        ///< Glag
    eGunjalaGondi = 41,        ///< Gong
    eMasaramGondi = 42,        ///< Gonm
    eGothic = 43,        ///< Goth
    eGrantha = 44,        ///< Gran
    eGreek = 45,        ///< Grek
    eGujarati = 46,        ///< Gujr
    eGurungKhema = 47,        ///< Gukh
    eGurmukhi = 48,        ///< Guru
    eHangul = 49,        ///< Hang
    eHan = 50,        ///< Hani
    eHanunoo = 51,        ///< Hano
    eHatran = 52,        ///< Hatr
    eHebrew = 53,        ///< Hebr
    eHiragana = 54,        ///< Hira
    eAnatolianHieroglyphs = 55,        ///< Hluw
    ePahawhHmong = 56,        ///< Hmng
    eNyiakengPuachueHmong = 57,        ///< Hmnp
    eKatakanaOrHiragana = 58,        ///< Hrkt
    eOldHungarian = 59,        ///< Hung
    eOldItalic = 60,        ///< Ital
    eJavanese = 61,        ///< Java
    eJurchen = 62,        ///< Jurc
    eKayahLi = 63,        ///< Kali
    eKatakana = 64,        ///< Kana
    eKawi = 65,        ///< Kawi
    eKharoshthi = 66,        ///< Khar
    eKhmer = 67,        ///< Khmr
    eKhojki = 68,        ///< Khoj
    eKhitanSmallScript = 69,        ///< Kits
    eKannada = 70,        ///< Knda
    eKiratRai = 71,        ///< Krai
    eKaithi = 72,        ///< Kthi
    eTaiTham = 73,        ///< Lana
    eLao = 74,        ///< Laoo
    eLatin = 75,        ///< Latn
    eLepcha = 76,        ///< Lepc
    eLimbu = 77,        ///< Limb
    eLinearA = 78,        ///< Lina
    eLinearB = 79,        ///< Linb
    eLisu = 80,        ///< Lisu
    eLycian = 81,        ///< Lyci
    eLydian = 82,        ///< Lydi
    eMahajani = 83,        ///< Mahj
    eMakasar = 84,        ///< Maka
    eMandaic = 85,        ///< Mand
    eManichaean = 86,        ///< Mani
    eMarchen = 87,        ///< Marc
    eMedefaidrin = 88,        ///< Medf
    eMendeKikakui = 89,        ///< Mend
    eMeroiticCursive = 90,        ///< Merc
    eMeroiticHieroglyphs = 91,        ///< Mero
    eMalayalam = 92,        ///< Mlym
    eModi = 93,        ///< Modi
    eMongolian = 94,        ///< Mong
    eMro = 95,        ///< Mroo
    eMeeteiMayek = 96,        ///< Mtei
    eMultani = 97,        ///< Mult
    eMyanmar = 98,        ///< Mymr
    eNagMundari = 99,        ///< Nagm
    eNandinagari = 100,        ///< Nand
    eOldNorthArabian = 101,        ///< Narb
    eNabataean = 102,        ///< Nbat
    eNewa = 103,        ///< Newa
    eNko = 104,        ///< Nkoo
    eNushu = 105,        ///< Nshu
    eOgham = 106,        ///< Ogam
    eOlChiki = 107,        ///< Olck
    eOlOnal = 108,        ///< Onao
    eOldTurkic = 109,        ///< Orkh
    eOriya = 110,        ///< Orya
    eOsage = 111,        ///< Osge
    eOsmanya = 112,        ///< Osma
    eOldUyghur = 113,        ///< Ougr
    ePalmyrene = 114,        ///< Palm
    ePauCinHau = 115,        ///< Pauc
    eProtoCuneiform = 116,        ///< Pcun
    eOldPermic = 117,        ///< Perm
    ePhagsPa = 118,        ///< Phag
    eInscriptionalPahlavi = 119,        ///< Phli
    ePsalterPahlavi = 120,        ///< Phlp
    ePhoenician = 121,        ///< Phnx
    eMiao = 122,        ///< Plrd
    eInscriptionalParthian = 123,        ///< Prti
    eRejang = 124,        ///< Rjng
    eHanifiRohingya = 125,        ///< Rohg
    eRunic = 126,        ///< Runr
    eSamaritan = 127,        ///< Samr
    eOldSouthArabian = 128,        ///< Sarb
    eSaurashtra = 129,        ///< Saur
    eSeal = 130,        ///< Seal
    eSignWriting = 131,        ///< Sgnw
    eShavian = 132,        ///< Shaw
    eSharada = 133,        ///< Shrd
    eSiddham = 134,        ///< Sidd
    eSidetic = 135,        ///< Sidt
    eKhudawadi = 136,        ///< Sind
    eSinhala = 137,        ///< Sinh
    eSogdian = 138,        ///< Sogd
    eOldSogdian = 139,        ///< Sogo
    eSoraSompeng = 140,        ///< Sora
    eSoyombo = 141,        ///< Soyo
    eSundanese = 142,        ///< Sund
    eSunuwar = 143,        ///< Sunu
    eSylotiNagri = 144,        ///< Sylo
    eSyriac = 145,        ///< Syrc
    eTagbanwa = 146,        ///< Tagb
    eTakri = 147,        ///< Takr
    eTaiLe = 148,        ///< Tale
    eNewTaiLue = 149,        ///< Talu
    eTamil = 150,        ///< Taml
    eTangut = 151,        ///< Tang
    eTaiViet = 152,        ///< Tavt
    eTaiYo = 153,        ///< Tayo
    eTelugu = 154,        ///< Telu
    eTifinagh = 155,        ///< Tfng
    eTagalog = 156,        ///< Tglg
    eThaana = 157,        ///< Thaa
    eThai = 158,        ///< Thai
    eTibetan = 159,        ///< Tibt
    eTirhuta = 160,        ///< Tirh
    eTangsa = 161,        ///< Tnsa
    eTodhri = 162,        ///< Todr
    eTolongSiki = 163,        ///< Tols
    eToto = 164,        ///< Toto
    eTuluTigalari = 165,        ///< Tutg
    eUgaritic = 166,        ///< Ugar
    eVai = 167,        ///< Vaii
    eVithkuqi = 168,        ///< Vith
    eWarangCiti = 169,        ///< Wara
    eWancho = 170,        ///< Wcho
    eOldPersian = 171,        ///< Xpeo
    eCuneiform = 172,        ///< Xsux
    eYezidi = 173,        ///< Yezi
    eYi = 174,        ///< Yiii
    eZanabazarSquare = 175,        ///< Zanb
    eInherited = 176,        ///< Zinh
    eCommon = 177,        ///< Zyyy
    eUnknown = 178,        ///< Zzzz
    kCount = 179
};

Values in the order of PropertyValueAliases.txt (short name in the comment).

enum

EAge

Ethereal::Text#
C++
enum class   EAge : std::uint8_t
{
    eV1_1 = 0,        ///< 1.1
    eV2_0 = 1,        ///< 2.0
    eV2_1 = 2,        ///< 2.1
    eV3_0 = 3,        ///< 3.0
    eV3_1 = 4,        ///< 3.1
    eV3_2 = 5,        ///< 3.2
    eV4_0 = 6,        ///< 4.0
    eV4_1 = 7,        ///< 4.1
    eV5_0 = 8,        ///< 5.0
    eV5_1 = 9,        ///< 5.1
    eV5_2 = 10,        ///< 5.2
    eV6_0 = 11,        ///< 6.0
    eV6_1 = 12,        ///< 6.1
    eV6_2 = 13,        ///< 6.2
    eV6_3 = 14,        ///< 6.3
    eV7_0 = 15,        ///< 7.0
    eV8_0 = 16,        ///< 8.0
    eV9_0 = 17,        ///< 9.0
    eV10_0 = 18,        ///< 10.0
    eV11_0 = 19,        ///< 11.0
    eV12_0 = 20,        ///< 12.0
    eV12_1 = 21,        ///< 12.1
    eV13_0 = 22,        ///< 13.0
    eV14_0 = 23,        ///< 14.0
    eV15_0 = 24,        ///< 15.0
    eV15_1 = 25,        ///< 15.1
    eV16_0 = 26,        ///< 16.0
    eV17_0 = 27,        ///< 17.0
    eV18_0 = 28,        ///< 18.0
    eUnassigned = 29,        ///< NA
    kCount = 30
};

Version that assigned a code point (Age), in the order of PropertyValueAliases.txt. The versions go up and eUnassigned is above all of them, so 'Age( cp ) <= EAge::eV16_0' tells whether cp exists in Unicode 16.0.

enum

EIndicConjunctBreak

Ethereal::Text#
C++
enum class   EIndicConjunctBreak : std::uint8_t
{
    eNone = 0,
    eLinker = 1,
    eConsonant = 2,
    eExtend = 3,
    kCount = 4
};
const

kExtendedPictographic

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kExtendedPictographic = 1u << 0;
const

kAlphabetic

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kAlphabetic = 1u << 1;
const

kWhiteSpace

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kWhiteSpace = 1u << 2;
const

kDefaultIgnorable

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kDefaultIgnorable = 1u << 3;
const

kEmojiPresentation

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kEmojiPresentation = 1u << 4;
const

kLowercase

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kLowercase = 1u << 5;
const

kUppercase

Ethereal::Text::CharFlags#
inline constexpr std::uint8_t kUppercase = 1u << 6;

text_idn.hpp

#include <ethereal/cpp/text/text_idn.hpp>

Internationalized domain names (UTS 46, RFC 3492) and confusables (UTS 39).

ToAscii and ToUnicode run the UTS 46 processing: mapping (case, widths, compatibility), NFC, splitting into labels, decoding the "xn--" labels, and validation (hyphens, leading marks, status, ContextJ for ZWJ and ZWNJ, the bidi rule of RFC 5893, and the STD3 rules for ASCII). The default options are the ones UTS 46 recommends for a client: nontransitional, with every check.

Every error is reported: eDomainInvalid and, in pErrors, the UTS 46 codes (IdnaError). The result is written anyway (the ToUnicode of an invalid name is useful to display it), and *pWritten is always the size of the result.

No dynamic memory. Each label is worked on the stack: a label with more than 256 code points after mapping gives IdnaError::kLabelTooLong (DNS accepts 63 bytes).

Confusables: Skeleton is the UTS 39 "skeleton" (NFD, without the ignorables, each code point by its prototype, NFD again). Two texts are confusable when they have the same skeleton: "paypal" with a Cyrillic 'а', "rn" and "m". It helps against homograph attacks in domains and user names. It does not replace a policy (UTS 39 has more: mixed scripts, restriction profiles).

struct

SIdnaOptions

Ethereal::Text#
C++
struct   SIdnaOptions
{
    /// @brief  Maps ß, ς, ZWJ and ZWNJ (the old behavior, not recommended).
    bool    bTransitional = false;

    /// @brief  In ASCII, only letters, digits and '-'.
    bool    bUseStd3AsciiRules = true;

    /// @brief  No '-' at the start or end, and no "--" in the 3rd and 4th positions.
    bool    bCheckHyphens = true;

    /// @brief  The bidi rule of RFC 5893.
    bool    bCheckBidi = true;

    /// @brief  The ContextJ of RFC 5892 (ZWJ, ZWNJ).
    bool    bCheckJoiners = true;

    /// @brief  ToAscii only: 1 to 63 bytes per label, 1 to 253 for the name.
    bool    bVerifyDnsLength = true;
};

UTS 46 processing options.

const

kP4

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kP4 = 1u << 0;

An invalid "xn--" (not ASCII, bad Punycode, or only ASCII).

const

kV1

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV1 = 1u << 1;

The label is not in NFC.

const

kV2

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV2 = 1u << 2;

"--" in the 3rd and 4th positions.

const

kV3

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV3 = 1u << 3;

'-' at the start or at the end.

const

kV4

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV4 = 1u << 4;

A decoded label that starts with "xn--".

const

kV5

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV5 = 1u << 5;

A '.' inside the label.

const

kV6

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV6 = 1u << 6;

Starts with a combining mark.

const

kV7

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kV7 = 1u << 7;

A disallowed code point (the status is not valid).

const

kU1

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kU1 = 1u << 8;

ASCII outside [a-z0-9-] (STD3).

const

kC1

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kC1 = 1u << 9;

ZWNJ out of context.

const

kC2

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kC2 = 1u << 10;

ZWJ out of context.

const

kB1

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kB1 = 1u << 11;

Bidi: the first is not L, R or AL.

const

kB2

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kB2 = 1u << 12;

Bidi: a class not allowed in an RTL label.

const

kB3

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kB3 = 1u << 13;

Bidi: an RTL label with a bad ending.

const

kB4

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kB4 = 1u << 14;

Bidi: EN and AN in the same RTL label.

const

kB5

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kB5 = 1u << 15;

Bidi: a class not allowed in an LTR label.

const

kB6

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kB6 = 1u << 16;

Bidi: an LTR label with a bad ending.

const

kA3

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kA3 = 1u << 17;

Punycode cannot encode the label.

const

kA4_1

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kA4_1 = 1u << 18;

The name has 0 or more than 253 bytes.

const

kA4_2

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kA4_2 = 1u << 19;

An empty label, or one with more than 63 bytes.

const

kX4_2

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kX4_2 = 1u << 20;

ToUnicode: an empty label (other than the root at the end).

const

kLabelTooLong

Ethereal::Text::IdnaError#
inline constexpr std::uint32_t kLabelTooLong = 1u << 21;

(This module) A label with more than 256 code points.

function

ToAscii

Ethereal::Text#
ETextStatus ToAscii( std::string_view sDomain, std::span< char > Out, std::size_t * pWritten, const SIdnaOptions & Options = {}, std::uint32_t * pErrors = nullptr ) noexcept;

The name in ASCII ("xn--..." for the labels that are not ASCII).

sDomain
The name, in UTF-8.
Out
Receives the result.
pWritten
Receives the size of the result.
Options
Processing options.
pErrors
Receives the IdnaError codes. May be null.
eOk, eDomainInvalid (with the codes in pErrors), eBufferTooSmall, eInvalidUtf8, or eInvalidArgument (pWritten null).
function

ToUnicode

Ethereal::Text#
ETextStatus ToUnicode( std::string_view sDomain, std::span< char > Out, std::size_t * pWritten, const SIdnaOptions & Options = {}, std::uint32_t * pErrors = nullptr ) noexcept;

The name in Unicode (the "xn--" labels decoded), mapped and in NFC.

sDomain
The name, in UTF-8.
Out
Receives the result.
pWritten
Receives the size of the result.
Options
Processing options.
pErrors
Receives the IdnaError codes. May be null.
Same as ToAscii.
function

PunycodeEncode

Ethereal::Text#
ETextStatus PunycodeEncode( std::string_view sUtf8, std::span< char > Out, std::size_t * pWritten ) noexcept;

Punycode (RFC 3492) of a UTF-8 text, without the "xn--" prefix.

sUtf8
The text.
Out
Receives the result.
pWritten
Receives the size needed.
eOk, eBufferTooSmall, eInvalidUtf8 or eDomainInvalid (overflow).
function

PunycodeDecode

Ethereal::Text#
ETextStatus PunycodeDecode( std::string_view sAscii, std::span< char > Out, std::size_t * pWritten ) noexcept;

The inverse, to UTF-8.

sAscii
The Punycode, without "xn--".
Out
Receives the result.
pWritten
Receives the size needed.
eOk, eBufferTooSmall, eDomainInvalid (invalid Punycode) or eSegmentTooLong (more than 256 code points).
function

Skeleton

Ethereal::Text#
ETextStatus Skeleton( std::string_view s, std::span< char > Out, std::size_t * pWritten ) noexcept;

The UTS 39 skeleton, in UTF-8. Each subpart of invalid UTF-8 is U+FFFD.

s
The text.
Out
Receives the skeleton.
pWritten
Receives the size needed.
eOk, eBufferTooSmall or eInvalidArgument (pWritten null).
function

AreConfusable

Ethereal::Text#
bool AreConfusable( std::string_view a, std::string_view b ) noexcept;

true when the two texts have the same skeleton. No dynamic memory, any size.

text_layout.hpp

#include <ethereal/cpp/text/text_layout.hpp>

Layout: line breaking (UAX 14), column width, truncation.

Line breaking. The break opportunities of UAX 14 (the default rules, with no dictionary for Thai, Khmer and the like), with the mandatory ones (after a line break, and at the end of the text) marked. Forward only: that is how it is used, filling lines from start to end.

Width, for terminals and monospaced fonts: 0 for controls, combining marks, ignorables and the Hangul vowels and finals. 2 for East_Asian_Width W and F. 1 for the rest (the "ambiguous" ones too, unless asked). A text is measured by grapheme: the grapheme takes the width of its widest code point, and 2 with the emoji presentation selector (U+FE0F) or in a flag (two regional indicators).

Truncation never splits a grapheme: not the flag, not the emoji family, not the letter with its accent. Nor the ellipsis.

The console uses this when Text is compiled (Cli::CodePointWidth, Cli::TextWidth, Cli::BytesForColumns). Without Text, it keeps its own table.

class

CLineBreakIterator

Ethereal::Text#

The line break opportunities of a text, from start to end.

class CLineBreakIterator
C++
CLineBreakIterator It( sText );
std::size_t uPos; bool bMandatory;
while( It.Next( &uPos, &bMandatory ) ) { ... }    //    the end of the text comes last
constructor

CLineBreakIterator

#
explicit CLineBreakIterator( std::string_view s ) noexcept;

Iterator at the start of s.

function

Next

#
bool Next( std::size_t * pPos, bool * pMandatory = nullptr ) noexcept;

The next opportunity, and whether it is mandatory.

The end of the text is always one (mandatory).

pPos
Receives the position, in bytes. Never 0.
pMandatory
Receives true for a mandatory break. May be null.
false after the end.
function

Position

#
std::size_t Position() const noexcept

Current position, in bytes.

function

WrapLine

Ethereal::Text#
std::size_t WrapLine( std::string_view s, std::size_t uColumns, std::size_t * pNext ) noexcept;
function

ColumnWidth

Ethereal::Text#
int ColumnWidth( char32_t cp, bool bAmbiguousWide = false ) noexcept;

Columns taken by one code point alone: 0, 1 or 2.

function

StringWidth

Ethereal::Text#
std::size_t StringWidth( std::string_view s, bool bAmbiguousWide = false ) noexcept;

Columns taken by the text (by grapheme, and 1 per subpart of invalid UTF-8).

function

TruncateToGraphemes

Ethereal::Text#
std::size_t TruncateToGraphemes( std::string_view s, std::size_t uMax ) noexcept;

The first uMax graphemes.

function

TruncateToWidth

Ethereal::Text#
std::size_t TruncateToWidth( std::string_view s, std::size_t uColumns, std::size_t * pWidth = nullptr ) noexcept;

The longest start that fits in uColumns columns. pWidth receives its width.

function

TruncateToBytes

Ethereal::Text#
std::size_t TruncateToBytes( std::string_view s, std::size_t uMaxBytes ) noexcept;

The longest start with at most uMaxBytes bytes.

function

TruncateWithEllipsis

Ethereal::Text#
ETextStatus TruncateWithEllipsis( std::string_view s, std::size_t uColumns, std::span< char > Out, std::size_t * pWritten, std::string_view sEllipsis = "\xE2\x80\xA6" ) noexcept;

The text in a width of uColumns, with an ellipsis when it does not fit.

When it fits, it comes out unchanged. Otherwise: the longest start that fits with sEllipsis after it (without its trailing spaces), and the ellipsis. When not even the ellipsis fits, only the start that fits comes out.

s
The text.
uColumns
Width available.
Out
Receives the result.
pWritten
Receives the size needed, also with eBufferTooSmall.
sEllipsis
The ellipsis. U+2026 by default.
eOk, eBufferTooSmall or eInvalidArgument.

text_normalize.hpp

#include <ethereal/cpp/text/text_normalize.hpp>

Normalization (UAX 15): NFC, NFD, NFKC, NFKD.

The path that matters is the one of already normalized text, which is almost all text. The quick check (the *_QC property and the order of the combining classes) confirms it in one pass and copies. ASCII goes 16 bytes at a time. Only the part that fails the check, from the last safe point before it, goes through decomposition, canonical ordering and composition, and copying resumes as soon as the text is normalized again.

No allocated memory and no size limit on a combining sequence. Up to 32 code points per segment are worked in a buffer on the stack. A larger segment (hundreds of marks on one letter) goes through a path that rereads the text instead of storing it: slower, and just as correct.

Hangul is arithmetic, with no table (11 172 syllables that the standard defines by formula).

enum

ENormalForm

Ethereal::Text#
C++
enum class   ENormalForm : std::uint8_t { eNFC = 0, eNFD, eNFKC, eNFKD };

The four normalization forms.

function

Normalize

Ethereal::Text#
ETextStatus Normalize( ENormalForm eForm, std::string_view sIn, std::span< char > Out, std::size_t * pWritten ) noexcept;

Normalizes sIn into Out. Rejects invalid UTF-8 (eInvalidUtf8).

eForm
The normalization form.
sIn
The text.
Out
Receives the result.
pWritten
Receives the size needed.
eOk, eBufferTooSmall, eInvalidUtf8 or eInvalidArgument.
function

IsNormalized

Ethereal::Text#
bool IsNormalized( ENormalForm eForm, std::string_view sIn ) noexcept;

true when the text is already in form eForm. false for invalid UTF-8.

Almost always decided by the quick check. Only the "maybe" cases normalize to compare.

eForm
The normalization form.
sIn
The text.
true when normalized.
class

CNormalizer

Ethereal::Text#

Normalization in chunks (a large file, a socket).

class CNormalizer

The result is the same as one call on the whole text, with the chunks split anywhere: in the middle of a combining sequence or of a UTF-8 character.

Keeps the end of each chunk, from the last safe point (where normalization cannot look back), in a fixed buffer of kCarryBytes. A combining sequence larger than that gives eSegmentTooLong (normal text has at most a few dozen bytes, and the "stream-safe" format of UAX 15 limits it to 31 code points). No allocated memory. With eBufferTooSmall the state does not change: repeat the same chunk with more space.

const

kCarryBytes

#
static constexpr std::size_t kCarryBytes = 1024;

Size of the buffer that carries the end of a chunk to the next.

constructor

CNormalizer

#
explicit CNormalizer( ENormalForm eForm = ENormalForm::eNFC ) noexcept : m_eForm( eForm )

Normalizer for the form eForm.

function

Feed

#
ETextStatus Feed( std::string_view sChunk, std::span< char > Out, std::size_t * pWritten ) noexcept;

Normalizes one chunk, keeping the part that may still change.

sChunk
The chunk.
Out
Receives the result.
pWritten
Receives the size needed.
eOk, eBufferTooSmall, eInvalidUtf8, eSegmentTooLong or eInvalidArgument.
function

Finish

#
ETextStatus Finish( std::span< char > Out, std::size_t * pWritten ) noexcept;

Writes what was kept. After this the normalizer goes back to the start.

Out
Receives the result.
pWritten
Receives the size needed.
eOk, eBufferTooSmall, eInvalidUtf8 or eInvalidArgument.

text_properties.hpp

#include <ethereal/cpp/text/text_properties.hpp>

Properties of a code point.

A three stage trie and an eight byte record. Every property the module uses in a loop (the category, bidi, line break, width, grapheme, word and sentence breaks, the script and the most requested binary properties) lives together: the 1226 combinations Unicode 18 actually has, and a trie that gives the record of each code point. The trie splits were chosen by measurement in the generator. A lookup is one call, three index reads and the record.

The tables are generated, not written by hand: 'tools/unicode_gen/gen_text.py' reads the UCD and writes them. Moving to a new Unicode version is one command and a review.

Out of range (above U+10FFFF), the properties are those of an unassigned code point (Cn, no script, neutral width, "other" classes).

function

UnicodeVersion

Ethereal::Text#
const char * UnicodeVersion() noexcept;

Unicode version of the tables ("18.0.0").

struct

SCharProperties

Ethereal::Text#
C++
struct   SCharProperties
{
    /// @brief  General_Category.
    EGeneralCategory    eGeneralCategory;

    /// @brief  Bidi_Class.
    EBidiClass            eBidiClass;

    /// @brief  Line_Break.
    ELineBreak            eLineBreak;

    /// @brief  East_Asian_Width (bits 0-2) and Sentence_Break (bits 3-6).
    std::uint8_t        uEastAsianWidthSentence;

    /// @brief  Grapheme_Cluster_Break (bits 0-4) and Indic_Conjunct_Break (bits 5-6).
    std::uint8_t        uGraphemeInCB;

    /// @brief  Word_Break.
    EWordBreak            eWordBreak;

    /// @brief  Binary properties, see CharFlags.
    std::uint8_t        uFlags;

    /// @brief  Script.
    EScript                eScript;


    /// @brief  East_Asian_Width.
    ///
    EEastAsianWidth EastAsianWidth() const noexcept            { return static_cast< EEastAsianWidth >( uEastAsianWidthSentence & 0x07u ); }

    /// @brief  Sentence_Break.
    ///
    ESentenceBreak SentenceBreak() const noexcept            { return static_cast< ESentenceBreak >( uEastAsianWidthSentence >> 3 ); }

    /// @brief  Grapheme_Cluster_Break.
    ///
    EGraphemeBreak GraphemeBreak() const noexcept            { return static_cast< EGraphemeBreak >( uGraphemeInCB & 0x1Fu ); }

    /// @brief  Indic_Conjunct_Break.
    ///
    EIndicConjunctBreak IndicConjunctBreak() const noexcept    { return static_cast< EIndicConjunctBreak >( uGraphemeInCB >> 5 ); }

    /// @brief  true when the CharFlags bit @p uFlag is set.
    ///
    bool Has( const std::uint8_t uFlag ) const noexcept        { return ( uFlags & uFlag ) != 0; }
};

The property record. Eight bytes, in the order of the generated table.

function

Properties

Ethereal::Text#
const SCharProperties & Properties( char32_t cp ) noexcept;

Properties of cp: a reference to the table record (no copy).

function

GeneralCategory

Ethereal::Text#
inline EGeneralCategory GeneralCategory( const char32_t cp ) noexcept

Shortcuts to one property of a code point.

function

Script

Ethereal::Text#
inline EScript Script( const char32_t cp ) noexcept
function

BidiClass

Ethereal::Text#
inline EBidiClass BidiClass( const char32_t cp ) noexcept
function

LineBreakClass

Ethereal::Text#
inline ELineBreak LineBreakClass( const char32_t cp ) noexcept
function

EastAsianWidth

Ethereal::Text#
inline EEastAsianWidth EastAsianWidth( const char32_t cp ) noexcept
function

GraphemeBreak

Ethereal::Text#
inline EGraphemeBreak GraphemeBreak( const char32_t cp ) noexcept
function

WordBreak

Ethereal::Text#
inline EWordBreak WordBreak( const char32_t cp ) noexcept
function

SentenceBreak

Ethereal::Text#
inline ESentenceBreak SentenceBreak( const char32_t cp ) noexcept
function

IsAlphabetic

Ethereal::Text#
inline bool IsAlphabetic( const char32_t cp ) noexcept

Shortcuts to the binary properties kept in the record.

function

IsWhitespace

Ethereal::Text#
inline bool IsWhitespace( const char32_t cp ) noexcept
function

IsLowercase

Ethereal::Text#
inline bool IsLowercase( const char32_t cp ) noexcept
function

IsUppercase

Ethereal::Text#
inline bool IsUppercase( const char32_t cp ) noexcept
function

IsExtendedPictographic

Ethereal::Text#
inline bool IsExtendedPictographic( const char32_t cp ) noexcept
function

IsDefaultIgnorable

Ethereal::Text#
inline bool IsDefaultIgnorable( const char32_t cp ) noexcept
function

IsPrintable

Ethereal::Text#
bool IsPrintable( char32_t cp ) noexcept;

"Printable" in the sense of the Unicode 'Graphic' (UTS 18).

Letters, marks, numbers, punctuation, symbols and the space separator (Zs). Not printable: control, format, surrogates, private use, unassigned, and the line and paragraph separators.

function

CombiningClass

Ethereal::Text#
std::uint8_t CombiningClass( char32_t cp ) noexcept;

Canonical combining class (0 for most code points).

struct

SNumericValue

Ethereal::Text#
C++
struct   SNumericValue
{
    /// @brief  Numerator.
    std::int64_t    iNumerator = 0;

    /// @brief  Denominator.
    std::uint32_t    uDenominator = 1;

    /// @brief  The value as a double.
    ///
    double Value() const noexcept    { return static_cast< double >( iNumerator ) / static_cast< double >( uDenominator ); }
};

Numeric_Value as an exact fraction.

function

NumericValue

Ethereal::Text#
bool NumericValue( char32_t cp, SNumericValue * pOut ) noexcept;

Numeric value of a code point.

cp
The code point.
pOut
Receives the value. May be null.
false when the code point has no numeric value.
function

Age

Ethereal::Text#
EAge Age( char32_t cp ) noexcept;

Version that assigned cp (the Age property, DerivedAge.txt).

eUnassigned for an unassigned code point and above U+10FFFF. The values are ordered, so 'Age( cp ) <= EAge::eV16_0' tells whether cp exists in Unicode 16.0. Lets a caller see the text as an older version of Unicode sees it: the regex engines of other libraries lag behind the tables of this module. The lookup is a trie of its own, the same cost as Properties().

function

ShortName

Ethereal::Text#
const char * ShortName( EGeneralCategory e ) noexcept;

Short and long name of each property value. "" outside the enumeration.

function

LongName

Ethereal::Text#
const char * LongName( EGeneralCategory e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( EBidiClass e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( EBidiClass e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( ELineBreak e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( ELineBreak e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( EEastAsianWidth e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( EEastAsianWidth e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( EGraphemeBreak e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( EGraphemeBreak e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( EWordBreak e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( EWordBreak e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( ESentenceBreak e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( ESentenceBreak e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( EScript e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( EScript e ) noexcept;
function

ShortName

Ethereal::Text#
const char * ShortName( EAge e ) noexcept;
function

LongName

Ethereal::Text#
const char * LongName( EAge e ) noexcept;
function

ScriptFromName

Ethereal::Text#
bool ScriptFromName( std::string_view sName, EScript * pOut ) noexcept;

The script by its short or long name ("Grek", "Greek").

Ignores case and '_', '-' and ' ' (the loose matching of UAX 44, LM3).

sName
The name.
pOut
Receives the script.
false when no script has that name.
function

GeneralCategoryFromName

Ethereal::Text#
bool GeneralCategoryFromName( std::string_view sName, EGeneralCategory * pOut ) noexcept;

The general category by its short or long name, with the same loose matching.

sName
The name.
pOut
Receives the category.
false when no category has that name.
function

AgeFromName

Ethereal::Text#
bool AgeFromName( std::string_view sName, EAge * pOut ) noexcept;

The age by its short or long name ("16.0", "V16_0", "NA", "Unassigned"), with the same loose matching.

sName
The name.
pOut
Receives the age.
false when no age has that name.

text_segment.hpp

#include <ethereal/cpp/text/text_segment.hpp>

Segmentation (UAX 29): graphemes, words, sentences.

The grapheme is what the user calls "a character": 'é' made of two parts, a flag made of two regional indicators, an emoji family made of seven code points joined by ZWJ. It is the right unit to move the cursor, count characters and cut text. Cutting in the middle of a grapheme splits the emoji in half.

Positions are bytes of the UTF-8 text, always at the start of a character. The boundaries include 0 and the end (in a non empty text).

Linear, also with hostile text. Walking a whole text with the iterator, forward or backward, is linear. Forward is a state machine (with lookahead only where a rule asks for it). Backward, each position is decided with the bounded context the rules need. The parity of the regional indicators (flags) is the only global thing: the iterator knows it because it stands on a boundary. PrevBoundary and IsBoundary on their own count the run of flags they fall in (linear in it).

Invalid UTF-8: each invalid subpart is a U+FFFD (and its own grapheme).

enum

EBreakKind

Ethereal::Text#
C++
enum class   EBreakKind : std::uint8_t { eGrapheme = 0, eWord, eSentence };

Kind of segment.

function

NextBoundary

Ethereal::Text#
std::size_t NextBoundary( EBreakKind eKind, std::string_view s, std::size_t i ) noexcept;

First boundary after i (the end, when there is no other).

function

PrevBoundary

Ethereal::Text#
std::size_t PrevBoundary( EBreakKind eKind, std::string_view s, std::size_t i ) noexcept;

Last boundary before i (0, when there is no other).

function

IsBoundary

Ethereal::Text#
bool IsBoundary( EBreakKind eKind, std::string_view s, std::size_t i ) noexcept;

true when i is a boundary of the given kind.

function

CountGraphemes

Ethereal::Text#
std::size_t CountGraphemes( std::string_view s ) noexcept;

Number of graphemes in the text.

class

CSegmentIterator

Ethereal::Text#

The segments of a text, forward and backward.

class CSegmentIterator
C++
CSegmentIterator It( EBreakKind::eWord, sText );
std::string_view sWord;
while( It.Next( &sWord ) ) { ... }

Forward, each Next continues from where the previous one stopped (without going back). Prev goes back from the current position. Seek moves the position to the boundary at or before i.

constructor

CSegmentIterator

#
CSegmentIterator( EBreakKind eKind, std::string_view s ) noexcept : m_eKind( eKind ), m_s( s )

Iterator at the start of s.

function

Next

#
bool Next( std::string_view * pSegment ) noexcept;

The segment after the current position, and advances. false at the end.

function

Prev

#
bool Prev( std::string_view * pSegment ) noexcept;

The segment before the current position, and goes back. false at the start.

function

Seek

#
void Seek( std::size_t i ) noexcept;

Moves to the boundary at or before i.

function

Position

#
std::size_t Position() const noexcept

Current position, in bytes.