(String line, BufferedReader reader)
| 580 | int start; //, stop; |
| 581 | |
| 582 | String[] handle(String line, BufferedReader reader) throws IOException { |
| 583 | // PApplet.println("handle() called for: " + line); |
| 584 | start = 0; |
| 585 | pieceCount = 0; |
| 586 | c = line.toCharArray(); |
| 587 | |
| 588 | // get tally of number of columns and allocate the array |
| 589 | int cols = 1; // the first comma indicates the second column |
| 590 | boolean quote = false; |
| 591 | for (int i = 0; i < c.length; i++) { |
| 592 | if (!quote && (c[i] == ',')) { |
| 593 | cols++; |
| 594 | } else if (c[i] == '\"') { |
| 595 | // double double quotes (escaped quotes like "") will simply toggle |
| 596 | // this back and forth, so it should remain accurate |
| 597 | quote = !quote; |
| 598 | } |
| 599 | } |
| 600 | pieces = new String[cols]; |
| 601 | |
| 602 | // while (offset < c.length) { |
| 603 | // start = offset; |
| 604 | while (start < c.length) { |
| 605 | boolean enough = ingest(); |
| 606 | while (!enough) { |
| 607 | // found a newline inside the quote, grab another line |
| 608 | String nextLine = reader.readLine(); |
| 609 | // System.out.println("extending to " + nextLine); |
| 610 | if (nextLine == null) { |
| 611 | // System.err.println(line); |
| 612 | throw new IOException("Found a quoted line that wasn't terminated properly."); |
| 613 | } |
| 614 | // for simplicity, not bothering to skip what's already been read |
| 615 | // from c (and reset the offset to 0), opting to make a bigger array |
| 616 | // with both lines. |
| 617 | char[] temp = new char[c.length + 1 + nextLine.length()]; |
| 618 | PApplet.arrayCopy(c, temp, c.length); |
| 619 | // NOTE: we're converting to \n here, which isn't perfect |
| 620 | temp[c.length] = '\n'; |
| 621 | nextLine.getChars(0, nextLine.length(), temp, c.length + 1); |
| 622 | // c = temp; |
| 623 | return handle(new String(temp), reader); |
| 624 | //System.out.println(" full line is now " + new String(c)); |
| 625 | //stop = nextComma(c, offset); |
| 626 | //System.out.println("stop is now " + stop); |
| 627 | //enough = ingest(); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | // Make any remaining entries blanks instead of nulls. Empty columns from |
| 632 | // CSV are always "" not null, so this handles successive commas in a line |
| 633 | for (int i = pieceCount; i < pieces.length; i++) { |
| 634 | pieces[i] = ""; |
| 635 | } |
| 636 | // PApplet.printArray(pieces); |
| 637 | return pieces; |
| 638 | } |
| 639 |
no test coverage detected