Ignore newline after EOT with a flag
Change-Id: Ia18cc0cbb1dda6311c6b2b8db1fae52c4b6335e0
diff --git a/token_writer.go b/token_writer.go
index 9f4088a..32c5a99 100644
--- a/token_writer.go
+++ b/token_writer.go
@@ -35,7 +35,7 @@
}
// Create a new token writer based on the options
-func NewTokenWriterFromOptions(w io.Writer, positionFlag bool) *TokenWriter {
+func NewTokenWriterFromOptions(w io.Writer, positionFlag bool, newlineAfterEot bool) *TokenWriter {
writer := bufio.NewWriter(w)
posC := 0
pos := make([]int, 0, 200)
@@ -49,11 +49,15 @@
// Store in []uint16
// and write to string
+ // Accept newline after EOT
+ if newlineAfterEot && posC == 0 && buf[0] == '\n' && writer.Buffered() != 0 {
+ posC--
+ }
+
posC += offset
pos = append(pos, posC)
posC += len(buf) - offset
pos = append(pos, posC)
- // pos = append(pos, offset, len(buf)-offset)
writer.WriteString(string(buf[offset:]))
writer.WriteRune('\n')
@@ -70,7 +74,7 @@
}
if positionFlag {
- tw.TextEnd = func(offset int) {
+ tw.TextEnd = func(_ int) {
writer.Flush()
writer.WriteString(strconv.Itoa(pos[0]))