diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 0ba12d8aa..b6128c786 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -6744,7 +6744,20 @@ public class PApplet implements PConstants { static public BufferedReader createReader(InputStream input) { InputStreamReader isr = new InputStreamReader(input, StandardCharsets.UTF_8); - return new BufferedReader(isr); + + BufferedReader reader = new BufferedReader(isr); + // consume the Unicode BOM (byte order marker) if present + try { + reader.mark(1); + int c = reader.read(); + // if not the BOM, back up to the beginning again + if (c != '\uFEFF') { + reader.reset(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return reader; } diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 4622d6413..8f6ce05d0 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -378,6 +378,15 @@ public class Table { } else { InputStreamReader isr = new InputStreamReader(input, encoding); BufferedReader reader = new BufferedReader(isr); + + // strip out the Unicode BOM, if present + reader.mark(1); + int c = reader.read(); + // if not the BOM, back up to the beginning again + if (c != '\uFEFF') { + reader.reset(); + } + /* if (awfulCSV) { parseAwfulCSV(reader, header); @@ -4039,6 +4048,7 @@ public class Table { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + /** * @webref table:method * @brief Trims whitespace from values diff --git a/core/todo.txt b/core/todo.txt index eee476aaf..e7552fe0e 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -2,7 +2,11 @@ X return null for PApplet.trim(null) X StringDict(TableRow) constructor X allow lone double quotes in the midst of csv strings -_ make trim() work on column titles as well +X make trim() work on column titles as well +_ add trimRows() and trimColumns() +_ would you ever use one w/o the other? +_ should trim() just handle it? +X consume Unicode BOM (0xFEFF) in createReader() and Table parser _ no prompt shows with selectInput() on 10.11 and 10.12