1
0
mirror of https://github.com/golang/go synced 2024-11-27 02:41:23 -07:00
go/src/encoding
Roger Peppe 6d95e5a4ff encoding/csv: add FieldPos method
This enables a consumer of a CSV to find out the position
of a CSV field without implementing an intermediate buffer.
This is useful to produce good higher level error messages when
the CSV syntax is OK but the field values don't match expectations.

This also changes the existing semantics of the `ParseError.Column`
field to bring it in line with precedent elsewhere in the Go
standard library (notably go/token.Position) - the column is
now 1-based and indicates a byte count rather than a rune count,
and the error position reporting at the end of a last line without
a newline is now fixed.

This change has some impact on performance:

```
name                                     old time/op    new time/op    delta
Read-8                                     2.14µs ± 0%    2.15µs ± 0%    ~     (p=0.056 n=5+5)
ReadWithFieldsPerRecord-8                  2.15µs ± 2%    2.15µs ± 1%    ~     (p=0.151 n=5+5)
ReadWithoutFieldsPerRecord-8               2.15µs ± 0%    2.15µs ± 0%  +0.37%  (p=0.024 n=5+5)
ReadLargeFields-8                          3.55µs ± 2%    3.59µs ± 0%    ~     (p=0.206 n=5+5)
ReadReuseRecord-8                          1.18µs ± 1%    1.22µs ± 1%  +2.93%  (p=0.008 n=5+5)
ReadReuseRecordWithFieldsPerRecord-8       1.18µs ± 0%    1.21µs ± 0%  +2.54%  (p=0.008 n=5+5)
ReadReuseRecordWithoutFieldsPerRecord-8    1.18µs ± 0%    1.22µs ± 1%  +3.66%  (p=0.008 n=5+5)
ReadReuseRecordLargeFields-8               2.53µs ± 1%    2.57µs ± 1%  +1.70%  (p=0.008 n=5+5)
Write-8                                    1.02µs ± 1%    1.01µs ± 0%  -1.18%  (p=0.016 n=5+4)
```

Fixes #44221.

Change-Id: Id37c50fc396024eef406c5bad45380ecd414f5ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/291290
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Paul Jolly <paul@myitcv.org.uk>
2021-04-29 17:47:48 +00:00
..
ascii85 all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
asn1 all: remove redundant spaces before . and , 2021-04-20 00:49:17 +00:00
base32 all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
base64 all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
binary encoding/binary: limit bytes read by Uvarint to <= 10 2021-03-08 18:49:14 +00:00
csv encoding/csv: add FieldPos method 2021-04-29 17:47:48 +00:00
gob all: remove redundant spaces before . and , 2021-04-20 00:49:17 +00:00
hex all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
json encoding/json: fix package shadowing in MarshalIndent example 2021-03-14 19:58:14 +00:00
pem all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
xml encoding/xml: replace comments inside directives with a space 2021-03-15 20:04:23 +00:00
encoding.go