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:
David Huynh 2010-03-09 19:10:55 +00:00
parent 8ce21461cb
commit 2bac6844e2

View File

@ -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 "
start = line.length(); while (start < line.length()) {
} else { int quote = line.indexOf('"', start);
text = line.substring(start, next + 1); if (quote < 0) {
start = next + 2; sb.append(line.substring(start));
} start = line.length();
break;
} else {
if (quote < line.length() - 1 && line.charAt(quote + 1) == '"') {
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) {