blob: e1fabdf0865f699ca5e3102b8815e48e10391114 [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
Akron32416ce2021-10-23 17:09:41 +020034func (tw *TokenWriterSimple) Token(offset int, buf []rune) {
35 tw.writer.WriteString(string(buf[offset:]))
Akrone396a932021-10-19 01:06:13 +020036 tw.writer.WriteRune('\n')
37}
38
39func (tw *TokenWriterSimple) Flush() error {
40 return tw.writer.Flush()
41}