Trims leading and trailing whitespace, such as spaces and tabs, from String table values. If no column is specified, then the values in all columns and rows are trimmed. A specific column may be referenced by either its ID or title. @webref table:method @webBrief Trims whitespace from values @see
()
| 4157 | * @see Table#removeTokens(String) |
| 4158 | */ |
| 4159 | public void trim() { |
| 4160 | columnTitles = PApplet.trim(columnTitles); |
| 4161 | for (int col = 0; col < getColumnCount(); col++) { |
| 4162 | trim(col); |
| 4163 | } |
| 4164 | // remove empty columns |
| 4165 | int lastColumn = getColumnCount() - 1; |
| 4166 | //while (isEmptyColumn(lastColumn) && lastColumn >= 0) { |
| 4167 | while (isEmptyArray(getStringColumn(lastColumn)) && lastColumn >= 0) { |
| 4168 | lastColumn--; |
| 4169 | } |
| 4170 | setColumnCount(lastColumn + 1); |
| 4171 | |
| 4172 | // trim() works from both sides |
| 4173 | while (getColumnCount() > 0 && isEmptyArray(getStringColumn(0))) { |
| 4174 | removeColumn(0); |
| 4175 | } |
| 4176 | |
| 4177 | // remove empty rows (starting from the end) |
| 4178 | int lastRow = lastRowIndex(); |
| 4179 | //while (isEmptyRow(lastRow) && lastRow >= 0) { |
| 4180 | while (isEmptyArray(getStringRow(lastRow)) && lastRow >= 0) { |
| 4181 | lastRow--; |
| 4182 | } |
| 4183 | setRowCount(lastRow + 1); |
| 4184 | |
| 4185 | while (getRowCount() > 0 && isEmptyArray(getStringRow(0))) { |
| 4186 | removeRow(0); |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | |
| 4191 | protected boolean isEmptyArray(String[] contents) { |
nothing calls this directly
no test coverage detected