Skip to content

Commit

Permalink
Merge pull request #38 from influxdata/rog-024-byte-column
Browse files Browse the repository at this point in the history
influxdata: use bytes for column offset
  • Loading branch information
rogpeppe authored Apr 12, 2021
2 parents 58e7c5b + 2d51648 commit a14ec47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions influxdata/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"time"
"unicode/utf8"
)

const (
Expand Down Expand Up @@ -821,7 +820,7 @@ func (d *Decoder) syntaxErrorf(offset int, f string, a ...interface{}) error {
} else {
columnBytes = buf
}
column := 1 + utf8.RuneCount(columnBytes)
column := len(columnBytes) + 1

// Note: line corresponds to the current line at d.r1, so if
// there are any newlines after the location of the error, we need to
Expand All @@ -843,7 +842,7 @@ func (d *Decoder) syntaxErrorf(offset int, f string, a ...interface{}) error {
type DecodeError struct {
// Line holds the one-based index of the line where the error occurred.
Line int64
// Column holds the one-based index of the column where the error occurred.
// Column holds the one-based index of the column (in bytes) where the error occurred.
Column int
// Err holds the underlying error.
Err error
Expand Down
6 changes: 3 additions & 3 deletions influxdata/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ func makeErrPositions(text string) (errPositions, string) {
buf = append(buf, text[:size]...)
default:
buf = append(buf, text[:size]...)
currPos.column++
currPos.column += size
}
text = text[size:]
}
Expand Down Expand Up @@ -1276,12 +1276,12 @@ func TestErrorPositions(t *testing.T) {
}, {
text: "a\nbác∑¹helélo∑²blah\n∑³x\n",
err: "foo: at line ∑¹: blah",
expectErr: "foo: at line 2:4: blah",
expectErr: "foo: at line 2:5: blah",
expectText: "a\nbácheléloblah\nx\n",
}, {
text: "a\nbác∑¹helélo∑²blah\n∑³x\n",
err: "foo: at line ∑²: blah",
expectErr: "foo: at line 2:10: blah",
expectErr: "foo: at line 2:12: blah",
expectText: "a\nbácheléloblah\nx\n",
}, {
text: "a\nbác∑¹helélo∑²blah\n∑³x\n",
Expand Down

0 comments on commit a14ec47

Please sign in to comment.