struct TermBuf::Unicode::Breaker

Overview

Decides where extended grapheme cluster boundaries fall, following the UAX #29 rules GB1 through GB999.

One instance walks one string. For each character in order, ask #boundary? whether a cluster boundary precedes it, then hand the same character to #consume to advance the state.

Defined in:

termbuf/unicode/grapheme.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

A fresh breaker, positioned before the first character of a string.


[View source]

Instance Method Detail

def boundary?(char : Char) : Bool #

Whether a cluster boundary falls immediately before char. ameba:disable Metrics/CyclomaticComplexity


[View source]
def consume(char : Char) : Nil #

Advances the state as though char had been added to the current cluster. Call exactly once per character, after #boundary?.


[View source]
def consume_ascii : Nil #

Advances the state for a printable ASCII character. Every code point in 0x20..0x7E has break class Other, conjunct class None, and no pictographic property, so none of the tables need consulting.


[View source]
def prepend_pending? : Bool #

Whether the character just consumed was a Prepend. That is the only way an ASCII character can join the cluster before it, so it is also the only case where the ASCII fast path in Unicode.each_grapheme is unsafe.


[View source]