public static List<String> splitSmart(String s,char separator){
  ArrayList<String> lst=new ArrayList<>(4);
  int pos=0, start=0, end=s.length();
  char inString=0;
  char ch=0;
  while (pos < end) {
    char prevChar=ch;
    ch=s.charAt(pos++);
    if (ch == '\\') {
      pos++;
    }
 else     if (inString != 0 && ch == inString) {
      inString=0;
    }
 else     if (ch == '\'' || ch == '"') {
      if (!Character.isLetterOrDigit(prevChar)) {
        inString=ch;
      }
    }
 else     if (ch == separator && inString == 0) {
      lst.add(s.substring(start,pos - 1));
      start=pos;
    }
  }
  if (start < end) {
    lst.add(s.substring(start,end));
  }
  return lst;
}

public static List < String > splitSmart ( String s , char separator ) { ArrayList < String > lst = new ArrayList < > ( 4 ) ; int pos = 0 , start = 0 , end = s . length ( ) ; char inString = 0 ; char ch = 0 ; while ( pos < end ) { char prevChar = ch ; ch = s . charAt ( pos ++ ) ; if ( ch == '\\' ) { pos ++ ; } else if ( inString != 0 && ch == inString ) { inString = 0 ; } else if ( ch == '\'' || ch == '"' ) { if ( ! Character . isLetterOrDigit ( prevChar ) ) { inString = ch ; } } else if ( ch == separator && inString == 0 ) { lst . add ( s . substring ( start , pos - 1 ) ) ; start = pos ; } } if ( start < end ) { lst . add ( s . substring ( start , end ) ) ; } return lst ; }
split a string based on a separator , but don ' t split if it ' s inside a string . assume ' \ ' escapes the next char both inside and outside strings .
