blob: 3ddcf27f8dc785e175afc6cd312d637fbd90ead3 [file] [log] [blame]
Akrone396a932021-10-19 01:06:13 +02001package datok
2
3import (
4 "bufio"
5 "io"
6)
7
8type TokenWriterI interface {
Akrona854faa2021-10-22 19:31:08 +02009 SentenceEnd(int)
10 TextEnd(int)
Akrone396a932021-10-19 01:06:13 +020011 Token(int, []rune)
12 Flush() error
13}
14
15var _ TokenWriterI = &TokenWriterSimple{}
16
17type TokenWriterSimple struct {
18 writer *bufio.Writer
19}
20
21func NewTokenWriterSimple(w io.Writer) *TokenWriterSimple {
22 return &TokenWriterSimple{bufio.NewWriter(w)}
23}
24
Akrona854faa2021-10-22 19:31:08 +020025func (tw *TokenWriterSimple) SentenceEnd(_ int) {
Akrone396a932021-10-19 01:06:13 +020026 tw.writer.WriteRune('\n')
27}
28
Akrona854faa2021-10-22 19:31:08 +020029func (tw *TokenWriterSimple) TextEnd(_ int) {
30 tw.writer.WriteRune('\n')
31 tw.writer.Flush()
32}
33
Akrone396a932021-10-19 01:06:13 +020034func (tw *TokenWriterSimple) Token(_ int, buf []rune) {
35 tw.writer.WriteString(string(buf))
36 tw.writer.WriteRune('\n')
37}
38
39func (tw *TokenWriterSimple) Flush() error {
40 return tw.writer.Flush()
41}