@@ -379,6 +379,15 @@ protected void parse(InputStream input, String options) throws IOException {
379
379
} else {
380
380
InputStreamReader isr = new InputStreamReader (input , encoding );
381
381
BufferedReader reader = new BufferedReader (isr );
382
+
383
+ // strip out the Unicode BOM, if present
384
+ reader .mark (1 );
385
+ int c = reader .read ();
386
+ // if not the BOM, back up to the beginning again
387
+ if (c != '\uFEFF' ) {
388
+ reader .reset ();
389
+ }
390
+
382
391
/*
383
392
if (awfulCSV) {
384
393
parseAwfulCSV(reader, header);
@@ -672,6 +681,12 @@ protected boolean ingest() {
672
681
addPiece (start , i , hasEscapedQuotes );
673
682
start = i +2 ;
674
683
return true ;
684
+
685
+ } else {
686
+ // This is a lone-wolf quote, occasionally seen in exports.
687
+ // It's a single quote in the middle of some other text,
688
+ // and not escaped properly. Pray for the best!
689
+ i ++;
675
690
}
676
691
677
692
} else { // not a quoted line
@@ -1791,7 +1806,7 @@ public void addColumn(String title) {
1791
1806
1792
1807
1793
1808
/**
1794
- * @param type the type to be used for the new column: INT, LONG, FLOAT, DOUBLE, STRING, or CATEGORY
1809
+ * @param type the type to be used for the new column: INT, LONG, FLOAT, DOUBLE, or STRING
1795
1810
*/
1796
1811
public void addColumn (String title , int type ) {
1797
1812
insertColumn (columns .length , title , type );
@@ -4034,17 +4049,78 @@ public void removeTokens(String tokens, String columnName) {
4034
4049
4035
4050
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4036
4051
4052
+
4037
4053
/**
4038
4054
* @webref table:method
4039
4055
* @brief Trims whitespace from values
4040
4056
* @see Table#removeTokens(String)
4041
4057
*/
4042
4058
public void trim () {
4059
+ columnTitles = PApplet .trim (columnTitles );
4043
4060
for (int col = 0 ; col < getColumnCount (); col ++) {
4044
4061
trim (col );
4045
4062
}
4063
+ // remove empty columns
4064
+ int lastColumn = getColumnCount () - 1 ;
4065
+ //while (isEmptyColumn(lastColumn) && lastColumn >= 0) {
4066
+ while (isEmptyArray (getStringColumn (lastColumn )) && lastColumn >= 0 ) {
4067
+ lastColumn --;
4068
+ }
4069
+ setColumnCount (lastColumn + 1 );
4070
+
4071
+ // trim() works from both sides
4072
+ while (getColumnCount () > 0 && isEmptyArray (getStringColumn (0 ))) {
4073
+ removeColumn (0 );
4074
+ }
4075
+
4076
+ // remove empty rows (starting from the end)
4077
+ int lastRow = lastRowIndex ();
4078
+ //while (isEmptyRow(lastRow) && lastRow >= 0) {
4079
+ while (isEmptyArray (getStringRow (lastRow )) && lastRow >= 0 ) {
4080
+ lastRow --;
4081
+ }
4082
+ setRowCount (lastRow + 1 );
4083
+
4084
+ while (getRowCount () > 0 && isEmptyArray (getStringRow (0 ))) {
4085
+ removeRow (0 );
4086
+ }
4046
4087
}
4047
4088
4089
+
4090
+ protected boolean isEmptyArray (String [] contents ) {
4091
+ for (String entry : contents ) {
4092
+ if (entry != null && entry .length () > 0 ) {
4093
+ return false ;
4094
+ }
4095
+ }
4096
+ return true ;
4097
+ }
4098
+
4099
+
4100
+ /*
4101
+ protected boolean isEmptyColumn(int column) {
4102
+ String[] contents = getStringColumn(column);
4103
+ for (String entry : contents) {
4104
+ if (entry != null && entry.length() > 0) {
4105
+ return false;
4106
+ }
4107
+ }
4108
+ return true;
4109
+ }
4110
+
4111
+
4112
+ protected boolean isEmptyRow(int row) {
4113
+ String[] contents = getStringRow(row);
4114
+ for (String entry : contents) {
4115
+ if (entry != null && entry.length() > 0) {
4116
+ return false;
4117
+ }
4118
+ }
4119
+ return true;
4120
+ }
4121
+ */
4122
+
4123
+
4048
4124
/**
4049
4125
* @param column ID number of the column to trim
4050
4126
*/
0 commit comments