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