src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

reader.go (610B)


      1 // Package graphemes implements Unicode grapheme cluster boundaries: https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries
      2 package graphemes
      3 
      4 import (
      5 	"bufio"
      6 	"io"
      7 )
      8 
      9 type Scanner struct {
     10 	*bufio.Scanner
     11 }
     12 
     13 // FromReader returns a Scanner, to split graphemes per
     14 // https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries.
     15 //
     16 // It embeds a [bufio.Scanner], so you can use its methods.
     17 //
     18 // Iterate through graphemes by calling Scan() until false, then check Err().
     19 func FromReader(r io.Reader) *Scanner {
     20 	sc := bufio.NewScanner(r)
     21 	sc.Split(SplitFunc)
     22 	return &Scanner{
     23 		Scanner: sc,
     24 	}
     25 }