public static List<String> unescape(String source,char escapeChar,char[] specialCharacters,char splitCharacter,int splitLimit){
  List<String> result=new LinkedList<>();
  StringBuilder b=new StringBuilder();
  boolean readEscape=false;
  int indexCount=-1;
  for (  char c : source.toCharArray()) {
    indexCount++;
    if (readEscape) {
      boolean found=false;
      if (c == splitCharacter) {
        found=true;
        b.append(c);
      }
 else       if (c == escapeChar) {
        found=true;
        b.append(c);
      }
 else {
        for (        char s : specialCharacters) {
          if (s == c) {
            found=true;
            b.append(c);
            break;
          }
        }
      }
      if (!found) {
        throw new IllegalArgumentException("String '" + source + "' contains illegal escaped character '"+ c+ "'.");
      }
      readEscape=false;
    }
 else     if (c == escapeChar) {
      readEscape=true;
    }
 else     if (c == splitCharacter) {
      readEscape=false;
      result.add(b.toString());
      if (splitLimit != -1) {
        if (result.size() == splitLimit - 1) {
          result.add(source.substring(indexCount + 1));
          return result;
        }
      }
      b=new StringBuilder();
    }
 else {
      readEscape=false;
      b.append(c);
    }
  }
  result.add(b.toString());
  return result;
}

public static List < String > unescape ( String source , char escapeChar , char [ ] specialCharacters , char splitCharacter , int splitLimit ) { List < String > result = new LinkedList < > ( ) ; StringBuilder b = new StringBuilder ( ) ; boolean readEscape = false ; int indexCount = - 1 ; for ( char c : source . toCharArray ( ) ) { indexCount ++ ; if ( readEscape ) { boolean found = false ; if ( c == splitCharacter ) { found = true ; b . append ( c ) ; } else if ( c == escapeChar ) { found = true ; b . append ( c ) ; } else { for ( char s : specialCharacters ) { if ( s == c ) { found = true ; b . append ( c ) ; break ; } } } if ( ! found ) { throw new IllegalArgumentException ( "String '" + source + "' contains illegal escaped character '" + c + "'." ) ; } readEscape = false ; } else if ( c == escapeChar ) { readEscape = true ; } else if ( c == splitCharacter ) { readEscape = false ; result . add ( b . toString ( ) ) ; if ( splitLimit != - 1 ) { if ( result . size ( ) == splitLimit - 1 ) { result . add ( source . substring ( indexCount + 1 ) ) ; return result ; } } b = new StringBuilder ( ) ; } else { readEscape = false ; b . append ( c ) ; } } result . add ( b . toString ( ) ) ; return result ; }
splits the string at every split character unless escaped . if the split limit is not - 1 , at most so many tokens will be returned . no more escaping is performed in the last token !
