Ignorer le champs ignore
This commit is contained in:
11
csvparser.go
11
csvparser.go
@@ -47,16 +47,12 @@ func (p *CsvParser) Parse(line string) (map[string]string, error) {
|
|||||||
indexMax := len(line) - 1
|
indexMax := len(line) - 1
|
||||||
for index, r := range line {
|
for index, r := range line {
|
||||||
if index == indexMax {
|
if index == indexMax {
|
||||||
if currentFieldIndex < len(p.fields) {
|
if currentFieldIndex < len(p.fields) && p.fields[currentFieldIndex] != "ignore" {
|
||||||
//fmt.Println("start:", valueStart, "end:", index)
|
|
||||||
//fmt.Println("Found a field value for:", p.fields[currentFieldIndex], line[valueStart:index])
|
|
||||||
if inEnclosedField && r == currentEncloserEnd {
|
if inEnclosedField && r == currentEncloserEnd {
|
||||||
ret[p.fields[currentFieldIndex]] = line[valueStart:index]
|
ret[p.fields[currentFieldIndex]] = line[valueStart:index]
|
||||||
} else {
|
} else {
|
||||||
ret[p.fields[currentFieldIndex]] = line[valueStart : index+1]
|
ret[p.fields[currentFieldIndex]] = line[valueStart : index+1]
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println("Index is:", index)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if r == '\\' {
|
if r == '\\' {
|
||||||
@@ -67,11 +63,8 @@ func (p *CsvParser) Parse(line string) (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
} else if r == p.delimiter {
|
} else if r == p.delimiter {
|
||||||
|
|
||||||
if currentFieldIndex < len(p.fields) {
|
if currentFieldIndex < len(p.fields) && p.fields[currentFieldIndex] != "ignore" {
|
||||||
//fmt.Println("start:", valueStart, "end:", index)
|
|
||||||
//fmt.Println("Found a field value for:", p.fields[currentFieldIndex], line[valueStart:index])
|
|
||||||
ret[p.fields[currentFieldIndex]] = line[valueStart:index]
|
ret[p.fields[currentFieldIndex]] = line[valueStart:index]
|
||||||
//fmt.Println("Index is:", index)
|
|
||||||
valueStart = index + 1
|
valueStart = index + 1
|
||||||
}
|
}
|
||||||
currentFieldIndex++
|
currentFieldIndex++
|
||||||
|
Reference in New Issue
Block a user