fix bug in CSV reader (read past end of line)

This commit is contained in:
Grahame Grieve 2020-04-06 10:11:00 +10:00
parent a52a1127f8
commit 3e49000188
1 changed files with 7 additions and 3 deletions

View File

@ -93,7 +93,11 @@ public class CSVReader extends InputStreamReader {
} }
public boolean has(String name) { public boolean has(String name) {
return cell(name) != null; for (int i = 0; i < cols.length; i++) {
if (name.equals(cols[i].trim()))
return cell(name) != null;
}
return false;
} }
public String cell(String name) { public String cell(String name) {
@ -103,7 +107,7 @@ public class CSVReader extends InputStreamReader {
index = i; index = i;
} }
if (index == -1) if (index == -1)
throw new Error("no cell "+name); throw new FHIRException("no cell "+name);
String s = cells.length >= index ? cells[index] : null; String s = cells.length >= index ? cells[index] : null;
if (Utilities.noString(s)) if (Utilities.noString(s))
return null; return null;
@ -149,7 +153,7 @@ public class CSVReader extends InputStreamReader {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
boolean inQuote = false; boolean inQuote = false;
while (inQuote || (peek() != '\r' && peek() != '\n')) { while (ready() && (inQuote || (peek() != '\r' && peek() != '\n'))) {
char c = peek(); char c = peek();
next(); next();
if (c == '"') { if (c == '"') {