Commit c4c3f2a1 authored by Russ Cox's avatar Russ Cox

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 <rsc@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarJoe Tsai <thebrokentoaster@gmail.com>
parent 9232a612
...@@ -64,7 +64,7 @@ import ( ...@@ -64,7 +64,7 @@ import (
// A ParseError is returned for parsing errors. // A ParseError is returned for parsing errors.
// Line numbers are 1-indexed and columns are 0-indexed. // Line numbers are 1-indexed and columns are 0-indexed.
type ParseError struct { type ParseError struct {
RecordLine int // Line where the record starts StartLine int // Line where the record starts
Line int // Line where the error occurred Line int // Line where the error occurred
Column int // Column (rune index) where the error occurred Column int // Column (rune index) where the error occurred
Err error // The actual error Err error // The actual error
...@@ -74,8 +74,8 @@ func (e *ParseError) Error() string { ...@@ -74,8 +74,8 @@ func (e *ParseError) Error() string {
if e.Err == ErrFieldCount { if e.Err == ErrFieldCount {
return fmt.Sprintf("record on line %d: %v", e.Line, e.Err) return fmt.Sprintf("record on line %d: %v", e.Line, e.Err)
} }
if e.RecordLine != e.Line { if e.StartLine != 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) 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) return fmt.Sprintf("parse error on line %d, column %d: %v", e.Line, e.Column, e.Err)
} }
...@@ -287,7 +287,7 @@ parseField: ...@@ -287,7 +287,7 @@ parseField:
if !r.LazyQuotes { if !r.LazyQuotes {
if j := bytes.IndexByte(field, '"'); j >= 0 { if j := bytes.IndexByte(field, '"'); j >= 0 {
col := utf8.RuneCount(fullLine[:len(fullLine)-len(line[j:])]) 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 break parseField
} }
} }
...@@ -327,7 +327,7 @@ parseField: ...@@ -327,7 +327,7 @@ parseField:
default: default:
// `"*` sequence (invalid non-escaped quote). // `"*` sequence (invalid non-escaped quote).
col := utf8.RuneCount(fullLine[:len(fullLine)-len(line)-quoteLen]) 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 break parseField
} }
} else if len(line) > 0 { } else if len(line) > 0 {
...@@ -345,7 +345,7 @@ parseField: ...@@ -345,7 +345,7 @@ parseField:
// Abrupt end of file (EOF or error). // Abrupt end of file (EOF or error).
if !r.LazyQuotes && errRead == nil { if !r.LazyQuotes && errRead == nil {
col := utf8.RuneCount(fullLine) 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 break parseField
} }
r.fieldIndexes = append(r.fieldIndexes, len(r.recordBuffer)) r.fieldIndexes = append(r.fieldIndexes, len(r.recordBuffer))
...@@ -375,7 +375,7 @@ parseField: ...@@ -375,7 +375,7 @@ parseField:
// Check or update the expected fields per record. // Check or update the expected fields per record.
if r.FieldsPerRecord > 0 { if r.FieldsPerRecord > 0 {
if len(dst) != r.FieldsPerRecord && err == nil { 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 { } else if r.FieldsPerRecord == 0 {
r.FieldsPerRecord = len(dst) r.FieldsPerRecord = len(dst)
......
...@@ -123,7 +123,7 @@ field"`, ...@@ -123,7 +123,7 @@ field"`,
}, { }, {
Name: "BadDoubleQuotes", Name: "BadDoubleQuotes",
Input: `a""b,c`, Input: `a""b,c`,
Error: &ParseError{RecordLine: 1, Line: 1, Column: 1, Err: ErrBareQuote}, Error: &ParseError{StartLine: 1, Line: 1, Column: 1, Err: ErrBareQuote},
}, { }, {
Name: "TrimQuote", Name: "TrimQuote",
Input: ` "a"," b",c`, Input: ` "a"," b",c`,
...@@ -132,25 +132,25 @@ field"`, ...@@ -132,25 +132,25 @@ field"`,
}, { }, {
Name: "BadBareQuote", Name: "BadBareQuote",
Input: `a "word","b"`, Input: `a "word","b"`,
Error: &ParseError{RecordLine: 1, Line: 1, Column: 2, Err: ErrBareQuote}, Error: &ParseError{StartLine: 1, Line: 1, Column: 2, Err: ErrBareQuote},
}, { }, {
Name: "BadTrailingQuote", Name: "BadTrailingQuote",
Input: `"a word",b"`, Input: `"a word",b"`,
Error: &ParseError{RecordLine: 1, Line: 1, Column: 10, Err: ErrBareQuote}, Error: &ParseError{StartLine: 1, Line: 1, Column: 10, Err: ErrBareQuote},
}, { }, {
Name: "ExtraneousQuote", Name: "ExtraneousQuote",
Input: `"a "word","b"`, Input: `"a "word","b"`,
Error: &ParseError{RecordLine: 1, Line: 1, Column: 3, Err: ErrQuote}, Error: &ParseError{StartLine: 1, Line: 1, Column: 3, Err: ErrQuote},
}, { }, {
Name: "BadFieldCount", Name: "BadFieldCount",
Input: "a,b,c\nd,e", Input: "a,b,c\nd,e",
Error: &ParseError{RecordLine: 2, Line: 2, Err: ErrFieldCount}, Error: &ParseError{StartLine: 2, Line: 2, Err: ErrFieldCount},
UseFieldsPerRecord: true, UseFieldsPerRecord: true,
FieldsPerRecord: 0, FieldsPerRecord: 0,
}, { }, {
Name: "BadFieldCount1", Name: "BadFieldCount1",
Input: `a,b,c`, Input: `a,b,c`,
Error: &ParseError{RecordLine: 1, Line: 1, Err: ErrFieldCount}, Error: &ParseError{StartLine: 1, Line: 1, Err: ErrFieldCount},
UseFieldsPerRecord: true, UseFieldsPerRecord: true,
FieldsPerRecord: 2, FieldsPerRecord: 2,
}, { }, {
...@@ -226,13 +226,13 @@ x,,, ...@@ -226,13 +226,13 @@ x,,,
}, },
ReuseRecord: true, ReuseRecord: true,
}, { }, {
Name: "RecordLine1", // Issue 19019 Name: "StartLine1", // Issue 19019
Input: "a,\"b\nc\"d,e", Input: "a,\"b\nc\"d,e",
Error: &ParseError{RecordLine: 1, Line: 2, Column: 1, Err: ErrQuote}, Error: &ParseError{StartLine: 1, Line: 2, Column: 1, Err: ErrQuote},
}, { }, {
Name: "RecordLine2", Name: "StartLine2",
Input: "a,b\n\"d\n\n,e", Input: "a,b\n\"d\n\n,e",
Error: &ParseError{RecordLine: 2, Line: 5, Column: 0, Err: ErrQuote}, Error: &ParseError{StartLine: 2, Line: 5, Column: 0, Err: ErrQuote},
}, { }, {
Name: "CRLFInQuotedField", // Issue 21201 Name: "CRLFInQuotedField", // Issue 21201
Input: "\"Hello\r\nHi\"", Input: "\"Hello\r\nHi\"",
...@@ -290,7 +290,7 @@ x,,, ...@@ -290,7 +290,7 @@ x,,,
}, { }, {
Name: "QuoteWithTrailingCRLF", Name: "QuoteWithTrailingCRLF",
Input: "\"foo\"bar\"\r\n", Input: "\"foo\"bar\"\r\n",
Error: &ParseError{RecordLine: 1, Line: 1, Column: 4, Err: ErrQuote}, Error: &ParseError{StartLine: 1, Line: 1, Column: 4, Err: ErrQuote},
}, { }, {
Name: "LazyQuoteWithTrailingCRLF", Name: "LazyQuoteWithTrailingCRLF",
Input: "\"foo\"bar\"\r\n", Input: "\"foo\"bar\"\r\n",
...@@ -307,7 +307,7 @@ x,,, ...@@ -307,7 +307,7 @@ x,,,
}, { }, {
Name: "OddQuotes", Name: "OddQuotes",
Input: `"""""""`, Input: `"""""""`,
Error: &ParseError{RecordLine: 1, Line: 1, Column: 7, Err: ErrQuote}, Error: &ParseError{StartLine: 1, Line: 1, Column: 7, Err: ErrQuote},
}, { }, {
Name: "LazyOddQuotes", Name: "LazyOddQuotes",
Input: `"""""""`, Input: `"""""""`,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment