Fixed csv importer to handle escaped quotation marks ("").
git-svn-id: http://google-refine.googlecode.com/svn/trunk@257 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
8ce21461cb
commit
2bac6844e2
@ -35,14 +35,31 @@ public class ImporterUtilities {
|
|||||||
String text = null;
|
String text = null;
|
||||||
|
|
||||||
if (line.charAt(start) == '"') {
|
if (line.charAt(start) == '"') {
|
||||||
int next = line.indexOf('"', start + 1);
|
StringBuffer sb = new StringBuffer();
|
||||||
if (next < 0) {
|
|
||||||
text = line.substring(start);
|
start++; // skip over "
|
||||||
|
while (start < line.length()) {
|
||||||
|
int quote = line.indexOf('"', start);
|
||||||
|
if (quote < 0) {
|
||||||
|
sb.append(line.substring(start));
|
||||||
start = line.length();
|
start = line.length();
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
text = line.substring(start, next + 1);
|
if (quote < line.length() - 1 && line.charAt(quote + 1) == '"') {
|
||||||
start = next + 2;
|
sb.append(line.substring(start, quote + 1)); // include " as well
|
||||||
|
start = quote + 2;
|
||||||
|
} else {
|
||||||
|
sb.append(line.substring(start, quote));
|
||||||
|
start = quote + 1;
|
||||||
|
if (start < line.length() && line.charAt(start) == ',') {
|
||||||
|
start++; // skip ,
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
text = sb.toString();
|
||||||
} else {
|
} else {
|
||||||
int next = line.indexOf(',', start);
|
int next = line.indexOf(',', start);
|
||||||
if (next < 0) {
|
if (next < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user