1 // Created as a template for Advanced Database Systems 2019
\r
3 import java.util.ArrayList;
\r
5 public class CSVSplitter {
\r
6 public static String[] split(String input){
\r
7 ArrayList<String> output = new ArrayList<String>();
\r
9 boolean insideQuote = false;
\r
11 for (int current = 0; current < input.length();current++){
\r
12 char c = input.charAt(current);
\r
16 output.add(input.substring(start,current));
\r
21 if (current == start) {
\r
23 } else if ( (current < input.length() - 1) && input.charAt(current+1) == '"'){ // escaped quote
\r
24 current = current + 1; // skip ahead
\r
26 } else if ( (current < input.length() - 1) && input.charAt(current+1) == ',') {
\r
27 insideQuote = false;
\r
32 output.add(input.substring(start));
\r
33 return output.toArray( new String[output.size()]);
\r
36 //This version does not consider quote when deciding splits
\r
37 public static String[] splitNoQuote(String input){
\r
38 ArrayList<String> output = new ArrayList<String>();
\r
40 boolean insideQuote = false;
\r
42 for (int current = 0; current < input.length();current++){
\r
43 char c = input.charAt(current);
\r
47 output.add(input.substring(start,current));
\r
54 output.add(input.substring(start));
\r
55 return output.toArray( new String[output.size()]);
\r