Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame^] | 1 | package datok |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "io" |
| 6 | ) |
| 7 | |
| 8 | type TokenWriterI interface { |
| 9 | SentenceEnd() |
| 10 | Token(int, []rune) |
| 11 | Flush() error |
| 12 | } |
| 13 | |
| 14 | var _ TokenWriterI = &TokenWriterSimple{} |
| 15 | |
| 16 | type TokenWriterSimple struct { |
| 17 | writer *bufio.Writer |
| 18 | } |
| 19 | |
| 20 | func NewTokenWriterSimple(w io.Writer) *TokenWriterSimple { |
| 21 | return &TokenWriterSimple{bufio.NewWriter(w)} |
| 22 | } |
| 23 | |
| 24 | func (tw *TokenWriterSimple) SentenceEnd() { |
| 25 | tw.writer.WriteRune('\n') |
| 26 | } |
| 27 | |
| 28 | func (tw *TokenWriterSimple) Token(_ int, buf []rune) { |
| 29 | tw.writer.WriteString(string(buf)) |
| 30 | tw.writer.WriteRune('\n') |
| 31 | } |
| 32 | |
| 33 | func (tw *TokenWriterSimple) Flush() error { |
| 34 | return tw.writer.Flush() |
| 35 | } |