Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
8c241fff65 | |
|
62296e1da6 |
14
csvparser.go
14
csvparser.go
|
@ -14,7 +14,9 @@ type CsvParser struct {
|
||||||
ignore string
|
ignore string
|
||||||
maxFieldIndex int
|
maxFieldIndex int
|
||||||
}
|
}
|
||||||
|
func (p *csvParser) FieldCount() int {
|
||||||
|
return maxFieldIndex + 1
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* delimiters: string with all delimiter chars
|
* delimiters: string with all delimiter chars
|
||||||
* mergeDelimiters: if true, all successive delimiters are considered as one
|
* mergeDelimiters: if true, all successive delimiters are considered as one
|
||||||
|
@ -107,12 +109,12 @@ func (p *CsvParser) Parse(line string) (map[string]string, error) {
|
||||||
|
|
||||||
// current rune is a delimiter, a value is present and the next char is the next value
|
// current rune is a delimiter, a value is present and the next char is the next value
|
||||||
if isDelimiter || index == maxIndex {
|
if isDelimiter || index == maxIndex {
|
||||||
if index == maxIndex && valueStart == -1 {
|
if index == maxIndex && valueStart == -1 {
|
||||||
valueStart = 0
|
valueStart = 0
|
||||||
}
|
}
|
||||||
state.delimiter = true
|
state.delimiter = true
|
||||||
field := line[valueStart:index +1]
|
field := line[valueStart : index+1]
|
||||||
field = strings.TrimRight(field,p.delimiters)
|
field = strings.TrimRight(field, p.delimiters)
|
||||||
if state.enclosed {
|
if state.enclosed {
|
||||||
field = strings.TrimRight(strings.TrimLeft(field, string(state.encloserStart)), string(state.encloserEnd))
|
field = strings.TrimRight(strings.TrimLeft(field, string(state.encloserStart)), string(state.encloserEnd))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue