#77 quote character as the second line

open
nobody
None
5
2011-09-08
2011-09-08
Anonymous
No

In the CSVReader cerca 250 line
you have the following code;

// the tricky case of an embedded quote in the middle: a,bc"d"ef,g
if(i>2 //not on the beginning of the line
which adds inner quotes to current cell data.
however the condition should be just if i>0.

Following example (quote character is ,) failes:
a"a"a,b"b'b
(in java "a\"a\"a"+","+"b\"b\"b"

as it results in

aa"a,b"b'b

and those values (for a and b) should be the same

PS: it would be benefical if you allowed as separator full String:

(the code is presented with the error described before + there are some changes in constructor)

} else {
inQuotes = !inQuotes;
// the tricky case of an embedded quote in the middle: a,bc"d"ef,g
if (i > separator.length() + 1 // ? not on the beginning of the line
&& i > this.separator.length()
&& !nextLine.substring(i - this.separator.length(), i).equals(this.separator) // not at the
// beginning of an
// escape sequence
&& nextLine.length() > (i + this.separator.length())
&& !nextLine.substring(i + 1, i + 1 + this.separator.length()).equals(this.separator) // not at
// the
// end of
// an
// escape sequence
) {
sb.append(c);
}
}
} else if (nextLine.length() >= i + separator.length()
&& nextLine.substring(i, i + separator.length()).equals(separator) && !inQuotes) {
tokensOnThisLine.add(sb.toString());
sb = new StringBuilder(INITIAL_READ_SIZE); // start work on next token
i += separator.length() - 1;
} else {
sb.append(c);
}

Discussion