Package-Level Type Names (total 4, in which 2 are exported)
/* sort exporteds by: | */
Type Parameters:
T: ~string | ~[]byte Iterator is a generic iterator for grapheme clusters in strings or byte slices,
with an ASCII hot path optimization. AnsiEscapeSequences treats 7-bit ANSI escape sequences (ECMA-48) as
single grapheme clusters when true. The default is false.
8-bit controls are not enabled by this option. See [AnsiEscapeSequences8Bit]. AnsiEscapeSequences8Bit treats 8-bit C1 ANSI escape sequences (ECMA-48) as single
grapheme clusters when true. The default is false.
8-bit control bytes are not UTF-8 encoded, i.e. not valid UTF-8. If you
choose this option, you are choosing to interpret non-UTF-8 data, caveat
emptor.dataTposintsplitfunc(T, bool) (int, T, error)startint End returns the byte position after the current grapheme in the original data. First returns the first grapheme cluster without advancing the iterator. Next advances the iterator to the next grapheme cluster.
Returns false when there are no more grapheme clusters. Reset resets the iterator to the beginning of the data. SetText sets the data for the iterator to operate on, and resets all state. Start returns the byte position of the current grapheme in the original data. Value returns the current grapheme cluster.
func FromBytes(b []byte) *Iterator[[]byte]
func FromString(s string) *Iterator[string]
Scanner*bufio.Scanner // Buffer used as argument to split. // Scan has finished. // Count of successive empty tokens. // End of data in buf. // Sticky error. // Maximum size of a token; modified by tests. // The reader provided by the client. // Scan has been called; buffer is in use. // The function to split the tokens. // First non-processed byte in buf. // Last token returned by split. Buffer controls memory allocation by the Scanner.
It sets the initial buffer to use when scanning
and the maximum size of buffer that may be allocated during scanning.
The contents of the buffer are ignored.
The maximum token size must be less than the larger of max and cap(buf).
If max <= cap(buf), [Scanner.Scan] will use this buffer only and do no allocation.
By default, [Scanner.Scan] uses an internal buffer and sets the
maximum token size to [MaxScanTokenSize].
Buffer panics if it is called after scanning has started. Bytes returns the most recent token generated by a call to [Scanner.Scan].
The underlying array may point to data that will be overwritten
by a subsequent call to Scan. It does no allocation. Err returns the first non-EOF error that was encountered by the [Scanner]. Scan advances the [Scanner] to the next token, which will then be
available through the [Scanner.Bytes] or [Scanner.Text] method. It returns false when
there are no more tokens, either by reaching the end of the input or an error.
After Scan returns false, the [Scanner.Err] method will return any error that
occurred during scanning, except that if it was [io.EOF], [Scanner.Err]
will return nil.
Scan panics if the split function returns too many empty
tokens without advancing the input. This is a common error mode for
scanners. Split sets the split function for the [Scanner].
The default split function is [ScanLines].
Split panics if it is called after scanning has started. Text returns the most recent token generated by a call to [Scanner.Scan]
as a newly allocated string holding its bytes. advance consumes n bytes of the buffer. It reports whether the advance was legal. setErr records the first error encountered.
func FromReader(r io.Reader) *Scanner
Package-Level Functions (total 13, in which 3 are exported)
FromBytes returns an iterator for the grapheme clusters in the input bytes.
Iterate while Next() is true, and access the grapheme via Value().
FromReader returns a Scanner, to split graphemes per
https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries.
It embeds a [bufio.Scanner], so you can use its methods.
Iterate through graphemes by calling Scan() until false, then check Err().
FromString returns an iterator for the grapheme clusters in the input string.
Iterate while Next() is true, and access the grapheme via Value().
Type Parameters:
T: ~string | ~[]byte ansiEscapeLength returns the byte length of a valid 7-bit ANSI escape
sequence at the start of data, or 0 if none.
Recognized forms (ECMA-48 / ISO 6429):
- CSI: ESC [ then parameter bytes (0x30-0x3F), intermediate (0x20-0x2F), final (0x40-0x7E)
- OSC: ESC ] then payload until BEL (0x07), 7-bit ST (ESC \), CAN (0x18), or SUB (0x1A)
- DCS, SOS, PM, APC: ESC P/X/^/_ then payload until 7-bit ST (ESC \), CAN, or SUB
- Two-byte: ESC + Fe/Fs (0x40-0x7E excluding above), or Fp (0x30-0x3F), or nF (0x20-0x2F then final)
Type Parameters:
T: ~string | ~[]byte ansiEscapeLength8Bit returns the byte length of a valid 8-bit C1 ANSI
sequence at the start of data, or 0 if none.
Recognized forms (ECMA-48 / ISO 6429):
- C1 CSI (0x9B) body as parameter/intermediate/final bytes
- C1 OSC (0x9D) body terminated by BEL, C1 ST, CAN, or SUB
- C1 DCS/SOS/PM/APC (0x90/0x98/0x9E/0x9F) body terminated by C1 ST, CAN, or SUB
- Standalone C1 controls (0x80..0x9F not listed above): single byte
Type Parameters:
T: ~string | ~[]byte csiBodyLength returns the length of the CSI body (param/intermediate/final bytes).
data is the slice after "ESC [".
Per ECMA-48, the CSI body has the form:
parameters (0x30–0x3F)*, intermediates (0x20–0x2F)*, final (0x40–0x7E)
Once an intermediate byte is seen, subsequent parameter bytes are invalid.
Type Parameters:
T: ~string | ~[]byte lookup returns the trie value for the first UTF-8 encoding in s and
the width in bytes of this encoding. The size will be 0 if s does not
hold enough bytes to complete the encoding. len(s) must be greater than 0.
lookupValue determines the type of block n and looks up the value for b.
Type Parameters:
T: ~string | ~[]byte oscLength returns the length of the OSC body.
data is the slice after "ESC ]".
Returns:
- n >= 0: consumed body length (includes BEL/ST terminator when present)
- -1: not terminated in the provided data
OSC accepts BEL (0x07) or 7-bit ST (ESC \) as terminators by widespread convention.
Per ECMA-48, CAN (0x18) and SUB (0x1A) cancel the control string; in that
case they are not part of the OSC sequence length.
Type Parameters:
T: ~string | ~[]byte oscLengthC1 returns the length of a C1 OSC body.
data is the slice after the C1 OSC initiator (0x9D).
Returns:
- n >= 0: consumed body length (includes BEL/ST terminator when present)
- -1: not terminated in the provided data
Terminators: BEL (0x07) or C1 ST (0x9C).
CAN (0x18) and SUB (0x1A) cancel the control string.
Type Parameters:
T: ~string | ~[]byte stSequenceLength returns the length of a control-string body.
data is the slice after "ESC x".
Returns:
- n >= 0: consumed body length (includes ST terminator when present)
- -1: not terminated in the provided data
Used for DCS, SOS, PM, and APC, which per ECMA-48 terminate with ST.
ST here is the 7-bit form (ESC \).
CAN (0x18) and SUB (0x1A) cancel the control string; in that case they are
not part of the sequence length.
Type Parameters:
T: ~string | ~[]byte stSequenceLengthC1 parses DCS/SOS/PM/APC bodies that terminate with C1 ST
(0x9C), or are canceled by CAN/SUB.
Package-Level Variables (total 5, in which 1 is exported)
SplitFunc is a bufio.SplitFunc implementation of Unicode grapheme cluster segmentation, for use with bufio.Scanner.
See https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries.
graphemesIndex: 25 blocks, 1600 entries, 1600 bytes
Block 0 is the zero block.
graphemesValues: 235 blocks, 15040 entries, 60160 bytes
The third block is the zero block.