Documentation ¶
Index ¶
- func RunesLen(p []Rune) (n int)
- type Iterable
- type IterableRune
- type Iterator
- type Rune
- func (r *Rune) Encode(p []byte) (n int, err error)
- func (r *Rune) Equals(a Rune) bool
- func (r *Rune) EqualsRune(a rune) bool
- func (r *Rune) IsError() bool
- func (r *Rune) Len() (n int)
- func (r *Rune) Read(p []byte) (n int, err error)
- func (r *Rune) Rune() rune
- func (r *Rune) Set(a Rune)
- func (r *Rune) SetRune(a rune)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Iterable ¶
type Iterable struct { Iterator // contains filtered or unexported fields }
Iterable defines a concrete implementation of an Iterator that provides type-agnostic methods over the interface.
func (*Iterable) GlyphCount ¶
GlyphCount scans the current range and counts the number of runes that are not within any escape sequence.
Once scanning completes, the receiver's internal indices are reset to their original value from when the method was called.
Note that only those runes that are in escape sequences which begin at or after the Iterator's first element (at RuneHead) will be excluded from the count. An example of this limitation is shown and discussed below.
Three different Iterators over the same backing array ([9]rune) are shown: [ 'H', 'l', 'o', ESC, '[', '2', 'D', 'e', 'l' ] // Backing array ==== ==== ==== ____ ____ ____ ____ ==== ==== { +1 +2 +3 -- -- -- -- +4 +5 } // (1.) 5 glyphs { +1 +2 +3 -- -- } // (2.) 3 glyphs { +1 +2 +3 +4 } // (3.) 4 glyphs The second and third Iterators together form the same sequence as the first Iterator, so their total number of glyphs (3 + 4) should logically equal the first (5). However, because the second and third Iterators' bounds were not aligned with the escape sequence's bounds, the final 2 runes of the escape sequence was erroneously counted as ordinary runes in the third Iterator.
func (*Iterable) Len ¶
Len scans the current range and counts the number of bytes required to encode each valid rune. Rune encodings that are invalid UTF-8 are considered to have zero bytes. Unlike GlyphCount, runes in escape sequences are included.
Once scanning completes, the receiver's internal indices are reset to their original value from when the method was called.
func (*Iterable) Next ¶
Next returns the next Rune in s.
If there are no elements remaining in s, returns a Rune r such that r.IsError() == true and r.Len() == 0.
func (*Iterable) Reset ¶
Reset resets the internal indices of s based on the backing Iterator's current head and tail indices.
func (*Iterable) Slice ¶
Slice sets the internal indices of s based on the backing Iterator's current head and tail indices offset by the given lo and hi slice indices.
Both lo and hi are relative to head and tail of s, such that lo=0 always refers to s's head index (even if s was previously sliced).
If lo and/or hi are negative, they are treated as unspecified slice indices. For example, Slice(-1, N) is equivalent to s[:N], Slice(N, -1) is to s[N:], and Slice(-1, -1) is to s[:] (also equivalent to Reset).
type IterableRune ¶
type IterableRune []rune
IterableRune implements Iterator using the native Go type []rune.
Use a construct like the following to convert an existing []rune to Iterable without causing a copy/alloc:
var aSlice = []rune{...} // Some global ... it := Iterable{Iterator: (*IterableRune)(&aSlice)}
var NonIterableRune IterableRune
func (*IterableRune) RuneAt ¶
func (ir *IterableRune) RuneAt(i int) *Rune
RuneAt returns a pointer to (*ir)[i]. Implements Iterator for native Go type []rune.
func (*IterableRune) RuneHead ¶
func (ir *IterableRune) RuneHead() uint32
RuneHead returns 0. Implements Iterator for native Go type []rune.
func (*IterableRune) RuneTail ¶
func (ir *IterableRune) RuneTail() uint32
RuneTail returns len(*ir). Implements Iterator for native Go type []rune.
type Iterator ¶
type Iterator interface { // RuneHead returns the index of the first Rune element. RuneHead() uint32 // RuneTail returns the index of the last Rune element. RuneTail() uint32 // RuneAt is the normal array-like accessor that returns a Rune for a given // 0-based list index. RuneAt(i int) *Rune }
Iterator defines a list of Rune randomly accessible by sequential index and terminated by head and tail indices.
This interface provides a []Rune accessor abstraction for structures that store Rune-like data in some other type such as the native Go type []rune.
type Rune ¶
type Rune rune
Rune extends type rune with unbuffered implementations of several interfaces from standard library package "io".
func (*Rune) Encode ¶
Encode writes into p the UTF-8 encoding of r and returns the number of bytes written. Returns 0, ErrWriteOverflow if p is not large enough to hold the encoding of r.
func (*Rune) EqualsRune ¶
EqualsRune returns true if and only if r and a are the same UTF-8 code point.