From c4c3f2a1f2d9ee0735aba1583bb2a3301ec790d3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 14 Nov 2017 13:23:10 -0500 Subject: encoding/csv: rename ParseError.RecordLine to .StartLine A record can span multiple lines (the whole reason for the extra field), so the important fact is that it's the _start_ of the record. Make that clear in the name. (This API was added during the Go 1.10 cycle so it can still be cleaned up.) Change-Id: Id95b3ceb7cdfc4aa0ed5a053cb84da8945fa5496 Reviewed-on: https://go-review.googlesource.com/78119 Run-TryBot: Russ Cox Reviewed-by: Brad Fitzpatrick Reviewed-by: Joe Tsai --- src/encoding/csv/reader.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/encoding/csv/reader.go') diff --git a/src/encoding/csv/reader.go b/src/encoding/csv/reader.go index 031ee6cedb..09f0dac5d0 100644 --- a/src/encoding/csv/reader.go +++ b/src/encoding/csv/reader.go @@ -64,18 +64,18 @@ import ( // A ParseError is returned for parsing errors. // Line numbers are 1-indexed and columns are 0-indexed. type ParseError struct { - RecordLine int // Line where the record starts - Line int // Line where the error occurred - Column int // Column (rune index) where the error occurred - Err error // The actual error + StartLine int // Line where the record starts + Line int // Line where the error occurred + Column int // Column (rune index) where the error occurred + Err error // The actual error } func (e *ParseError) Error() string { if e.Err == ErrFieldCount { return fmt.Sprintf("record on line %d: %v", e.Line, e.Err) } - if e.RecordLine != e.Line { - return fmt.Sprintf("record on line %d; parse error on line %d, column %d: %v", e.RecordLine, e.Line, e.Column, e.Err) + if e.StartLine != e.Line { + return fmt.Sprintf("record on line %d; parse error on line %d, column %d: %v", e.StartLine, e.Line, e.Column, e.Err) } return fmt.Sprintf("parse error on line %d, column %d: %v", e.Line, e.Column, e.Err) } @@ -287,7 +287,7 @@ parseField: if !r.LazyQuotes { if j := bytes.IndexByte(field, '"'); j >= 0 { col := utf8.RuneCount(fullLine[:len(fullLine)-len(line[j:])]) - err = &ParseError{RecordLine: recLine, Line: r.numLine, Column: col, Err: ErrBareQuote} + err = &ParseError{StartLine: recLine, Line: r.numLine, Column: col, Err: ErrBareQuote} break parseField } } @@ -327,7 +327,7 @@ parseField: default: // `"*` sequence (invalid non-escaped quote). col := utf8.RuneCount(fullLine[:len(fullLine)-len(line)-quoteLen]) - err = &ParseError{RecordLine: recLine, Line: r.numLine, Column: col, Err: ErrQuote} + err = &ParseError{StartLine: recLine, Line: r.numLine, Column: col, Err: ErrQuote} break parseField } } else if len(line) > 0 { @@ -345,7 +345,7 @@ parseField: // Abrupt end of file (EOF or error). if !r.LazyQuotes && errRead == nil { col := utf8.RuneCount(fullLine) - err = &ParseError{RecordLine: recLine, Line: r.numLine, Column: col, Err: ErrQuote} + err = &ParseError{StartLine: recLine, Line: r.numLine, Column: col, Err: ErrQuote} break parseField } r.fieldIndexes = append(r.fieldIndexes, len(r.recordBuffer)) @@ -375,7 +375,7 @@ parseField: // Check or update the expected fields per record. if r.FieldsPerRecord > 0 { if len(dst) != r.FieldsPerRecord && err == nil { - err = &ParseError{RecordLine: recLine, Line: recLine, Err: ErrFieldCount} + err = &ParseError{StartLine: recLine, Line: recLine, Err: ErrFieldCount} } } else if r.FieldsPerRecord == 0 { r.FieldsPerRecord = len(dst) -- cgit v1.3