public static List<String> parseArguments(String functionCall) throws FBSQLParseException {
  functionCall=functionCall.trim();
  checkSyntax(functionCall);
  final int parenthesisStart=functionCall.indexOf('(');
  if (parenthesisStart == -1) {
    return Collections.emptyList();
  }
  final String paramsString=functionCall.substring(parenthesisStart + 1,functionCall.length() - 1);
  final List<String> params=new ArrayList<String>();
  final StringBuilder sb=new StringBuilder();
  boolean inQuotes=false;
  boolean inDoubleQuotes=false;
  boolean coalesceSpace=true;
  int nestedParentheses=0;
  for (int i=0, n=paramsString.length(); i < n; i++) {
    char currentChar=paramsString.charAt(i);
    if (Character.isWhitespace(currentChar)) {
      if (inQuotes || inDoubleQuotes) {
        sb.append(currentChar);
      }
 else       if (!coalesceSpace) {
        sb.append(' ');
        coalesceSpace=true;
      }
      continue;
    }
switch (currentChar) {
case '\'':
      sb.append(currentChar);
    if (!inDoubleQuotes)     inQuotes=!inQuotes;
  coalesceSpace=false;
break;
case '"':
sb.append(currentChar);
if (!inQuotes) inDoubleQuotes=!inDoubleQuotes;
coalesceSpace=false;
break;
case '(':
if (!(inQuotes || inDoubleQuotes)) {
nestedParentheses++;
}
sb.append('(');
coalesceSpace=false;
break;
case ')':
if (!(inQuotes || inDoubleQuotes)) {
nestedParentheses--;
if (nestedParentheses < 0) {
throw new FBSQLParseException("Unbalanced parentheses in parameters at position " + i);
}
}
sb.append(')');
coalesceSpace=false;
break;
case ',':
if (inQuotes || inDoubleQuotes || nestedParentheses > 0) {
sb.append(currentChar);
}
 else {
params.add(sb.toString());
sb.setLength(0);
coalesceSpace=true;
}
break;
default :
sb.append(currentChar);
coalesceSpace=false;
}
}
if (sb.length() > 0) params.add(sb.toString());
if (inQuotes || inDoubleQuotes) {
throw new FBSQLParseException("String literal is not properly closed.");
}
if (nestedParentheses != 0) {
throw new FBSQLParseException("Unbalanced parentheses in parameters.");
}
return params;
}

public static List < String > parseArguments ( String functionCall ) throws FBSQLParseException { functionCall = functionCall . trim ( ) ; checkSyntax ( functionCall ) ; final int parenthesisStart = functionCall . indexOf ( '(' ) ; if ( parenthesisStart == - 1 ) { return Collections . emptyList ( ) ; } final String paramsString = functionCall . substring ( parenthesisStart + 1 , functionCall . length ( ) - 1 ) ; final List < String > params = new ArrayList < String > ( ) ; final StringBuilder sb = new StringBuilder ( ) ; boolean inQuotes = false ; boolean inDoubleQuotes = false ; boolean coalesceSpace = true ; int nestedParentheses = 0 ; for ( int i = 0 , n = paramsString . length ( ) ; i < n ; i ++ ) { char currentChar = paramsString . charAt ( i ) ; if ( Character . isWhitespace ( currentChar ) ) { if ( inQuotes || inDoubleQuotes ) { sb . append ( currentChar ) ; } else if ( ! coalesceSpace ) { sb . append ( ' ' ) ; coalesceSpace = true ; } continue ; } switch ( currentChar ) { case '\'' : sb . append ( currentChar ) ; if ( ! inDoubleQuotes ) inQuotes = ! inQuotes ; coalesceSpace = false ; break ; case '"' : sb . append ( currentChar ) ; if ( ! inQuotes ) inDoubleQuotes = ! inDoubleQuotes ; coalesceSpace = false ; break ; case '(' : if ( ! ( inQuotes || inDoubleQuotes ) ) { nestedParentheses ++ ; } sb . append ( '(' ) ; coalesceSpace = false ; break ; case ')' : if ( ! ( inQuotes || inDoubleQuotes ) ) { nestedParentheses -- ; if ( nestedParentheses < 0 ) { throw new FBSQLParseException ( "Unbalanced parentheses in parameters at position " + i ) ; } } sb . append ( ')' ) ; coalesceSpace = false ; break ; case ',' : if ( inQuotes || inDoubleQuotes || nestedParentheses > 0 ) { sb . append ( currentChar ) ; } else { params . add ( sb . toString ( ) ) ; sb . setLength ( 0 ) ; coalesceSpace = true ; } break ; default : sb . append ( currentChar ) ; coalesceSpace = false ; } } if ( sb . length ( ) > 0 ) params . add ( sb . toString ( ) ) ; if ( inQuotes || inDoubleQuotes ) { throw new FBSQLParseException ( "String literal is not properly closed." ) ; } if ( nestedParentheses != 0 ) { throw new FBSQLParseException ( "Unbalanced parentheses in parameters." ) ; } return params ; }
extract function arguments from the function call . this method parses escaped function call string and extracts function parameters from it .
