public String[] splitAndSQLEscape() throws QueryException {
  if (pathString == null)   throwException(QueryMessage.EX_EMPTY_PATH);
  int pathLen=pathString.length;
  ArrayList<String> result=new ArrayList<String>(10);
  StringBuilder sb=new StringBuilder(Math.max(pathLen * 2 + 2,128));
  boolean inQuotes=false;
  boolean inArray=false;
  boolean needsQuotes=false;
  boolean allowArray=true;
  boolean afterArray=false;
  boolean quotedStep=false;
  int pos=0;
  sb.append(SQL_DELIMITER);
  if (pathLen == 0) {
    allowArray=false;
    needsQuotes=true;
  }
  while (pos < pathString.length) {
    char currentChar=pathString[pos];
switch (currentChar) {
case SEG_DELIMITER:
      if ((afterArray) || (quotedStep))       throwPathException(QueryMessage.EX_MISSING_STEP_DOT,pos);
    if (!inQuotes) {
      if (sb.length() > 1)       throwPathException(QueryMessage.EX_BAD_BACKQUOTE,pos);
      inQuotes=true;
      ++pos;
      break;
    }
  ++pos;
if (pos < pathString.length) {
  currentChar=pathString[pos];
  if (currentChar == SEG_DELIMITER) {
    sb.append(currentChar);
    ++pos;
    needsQuotes=true;
    break;
  }
}
if (sb.length() == 1) {
needsQuotes=true;
}
inQuotes=false;
quotedStep=true;
break;
case ARRAY_STOP:
if (inArray) {
inArray=false;
String arrStep=buildArrayStep(sb);
validateArrayStep(arrStep);
result.add(arrStep);
afterArray=true;
++pos;
break;
}
 else if (!inQuotes) {
if (currentChar == ARRAY_STOP) throwPathException(QueryMessage.EX_PATH_SYNTAX_ERROR,pos);
}
case ARRAY_START:
case STEP_SEPARATOR:
if ((!inQuotes) && (!inArray)) {
inArray=(currentChar == ARRAY_START);
if ((sb.length() > 1) || quotedStep) {
result.add(buildStep(sb,needsQuotes,quotedStep));
}
 else if (!inArray) {
if (!afterArray) {
result.add(buildStep(sb,true,quotedStep));
}
}
 else {
if (!allowArray) {
result.add(buildStep(sb,true,quotedStep));
}
}
quotedStep=false;
allowArray=inArray;
needsQuotes=false;
afterArray=false;
++pos;
if (inArray) {
sb.setLength(0);
sb.append(ARRAY_START);
}
 else {
if (pos >= pathString.length) {
needsQuotes=true;
}
}
break;
}
default :
if ((afterArray) || (quotedStep)) throwPathException(QueryMessage.EX_MISSING_STEP_DOT,pos);
allowArray=true;
if (currentChar == '\'') {
sb.append(currentChar);
sb.append(currentChar);
needsQuotes=true;
}
 else if ((currentChar == SQL_DELIMITER) || (currentChar == ESCAPE_CHAR)) {
needsQuotes=true;
sb.append(ESCAPE_CHAR);
sb.append(currentChar);
}
 else if (currentChar < ' ') {
sb.append(ESCAPE_CHAR);
switch (currentChar) {
case '\n':
sb.append('n');
break;
case '\r':
sb.append('r');
break;
case '\t':
sb.append('t');
break;
default :
Formatter fmt=new Formatter(sb);
fmt.format("u%04x",(int)currentChar);
fmt.close();
break;
}
needsQuotes=true;
}
 else {
if (!needsQuotes) {
int idx=ALPHA_NUM_UNDER.indexOf(currentChar);
if (idx < 0) needsQuotes=true;
 else if ((sb.length() == 1) && (idx >= IS_DIGIT_POS)) needsQuotes=true;
}
sb.append(currentChar);
}
++pos;
break;
}
}
if (inArray) throwException(QueryMessage.EX_UNCLOSED_STEP,"array",new String(pathString));
if (inQuotes) throwException(QueryMessage.EX_UNCLOSED_STEP,"quote",new String(pathString));
if (sb.length() > 1 || !allowArray || quotedStep) result.add(buildStep(sb,needsQuotes,quotedStep));
String[] stepArr=new String[result.size()];
return (result.toArray(stepArr));
}

public String [ ] splitAndSQLEscape ( ) throws QueryException { if ( pathString == null ) throwException ( QueryMessage . EX_EMPTY_PATH ) ; int pathLen = pathString . length ; ArrayList < String > result = new ArrayList < String > ( 10 ) ; StringBuilder sb = new StringBuilder ( Math . max ( pathLen * 2 + 2 , 128 ) ) ; boolean inQuotes = false ; boolean inArray = false ; boolean needsQuotes = false ; boolean allowArray = true ; boolean afterArray = false ; boolean quotedStep = false ; int pos = 0 ; sb . append ( SQL_DELIMITER ) ; if ( pathLen == 0 ) { allowArray = false ; needsQuotes = true ; } while ( pos < pathString . length ) { char currentChar = pathString [ pos ] ; switch ( currentChar ) { case SEG_DELIMITER : if ( ( afterArray ) || ( quotedStep ) ) throwPathException ( QueryMessage . EX_MISSING_STEP_DOT , pos ) ; if ( ! inQuotes ) { if ( sb . length ( ) > 1 ) throwPathException ( QueryMessage . EX_BAD_BACKQUOTE , pos ) ; inQuotes = true ; ++ pos ; break ; } ++ pos ; if ( pos < pathString . length ) { currentChar = pathString [ pos ] ; if ( currentChar == SEG_DELIMITER ) { sb . append ( currentChar ) ; ++ pos ; needsQuotes = true ; break ; } } if ( sb . length ( ) == 1 ) { needsQuotes = true ; } inQuotes = false ; quotedStep = true ; break ; case ARRAY_STOP : if ( inArray ) { inArray = false ; String arrStep = buildArrayStep ( sb ) ; validateArrayStep ( arrStep ) ; result . add ( arrStep ) ; afterArray = true ; ++ pos ; break ; } else if ( ! inQuotes ) { if ( currentChar == ARRAY_STOP ) throwPathException ( QueryMessage . EX_PATH_SYNTAX_ERROR , pos ) ; } case ARRAY_START : case STEP_SEPARATOR : if ( ( ! inQuotes ) && ( ! inArray ) ) { inArray = ( currentChar == ARRAY_START ) ; if ( ( sb . length ( ) > 1 ) || quotedStep ) { result . add ( buildStep ( sb , needsQuotes , quotedStep ) ) ; } else if ( ! inArray ) { if ( ! afterArray ) { result . add ( buildStep ( sb , true , quotedStep ) ) ; } } else { if ( ! allowArray ) { result . add ( buildStep ( sb , true , quotedStep ) ) ; } } quotedStep = false ; allowArray = inArray ; needsQuotes = false ; afterArray = false ; ++ pos ; if ( inArray ) { sb . setLength ( 0 ) ; sb . append ( ARRAY_START ) ; } else { if ( pos >= pathString . length ) { needsQuotes = true ; } } break ; } default : if ( ( afterArray ) || ( quotedStep ) ) throwPathException ( QueryMessage . EX_MISSING_STEP_DOT , pos ) ; allowArray = true ; if ( currentChar == '\'' ) { sb . append ( currentChar ) ; sb . append ( currentChar ) ; needsQuotes = true ; } else if ( ( currentChar == SQL_DELIMITER ) || ( currentChar == ESCAPE_CHAR ) ) { needsQuotes = true ; sb . append ( ESCAPE_CHAR ) ; sb . append ( currentChar ) ; } else if ( currentChar < ' ' ) { sb . append ( ESCAPE_CHAR ) ; switch ( currentChar ) { case '\n' : sb . append ( 'n' ) ; break ; case '\r' : sb . append ( 'r' ) ; break ; case '\t' : sb . append ( 't' ) ; break ; default : Formatter fmt = new Formatter ( sb ) ; fmt . format ( "u%04x" , ( int ) currentChar ) ; fmt . close ( ) ; break ; } needsQuotes = true ; } else { if ( ! needsQuotes ) { int idx = ALPHA_NUM_UNDER . indexOf ( currentChar ) ; if ( idx < 0 ) needsQuotes = true ; else if ( ( sb . length ( ) == 1 ) && ( idx >= IS_DIGIT_POS ) ) needsQuotes = true ; } sb . append ( currentChar ) ; } ++ pos ; break ; } } if ( inArray ) throwException ( QueryMessage . EX_UNCLOSED_STEP , "array" , new String ( pathString ) ) ; if ( inQuotes ) throwException ( QueryMessage . EX_UNCLOSED_STEP , "quote" , new String ( pathString ) ) ; if ( sb . length ( ) > 1 || ! allowArray || quotedStep ) result . add ( buildStep ( sb , needsQuotes , quotedStep ) ) ; String [ ] stepArr = new String [ result . size ( ) ] ; return ( result . toArray ( stepArr ) ) ; }
parse the path into an array of steps . the steps are suitable for assembly into a single single - quoted literal , meaning that any necessary escaping and / or double quoting has been done . returns null if the path cannot be parsed properly .
