public static int skipCQLValue ( String toParse , int idx ) { if ( idx >= toParse . length ( ) ) throw new IllegalArgumentException ( ) ; if ( isBlank ( toParse . charAt ( idx ) ) ) throw new IllegalArgumentException ( ) ; int cbrackets = 0 ; int sbrackets = 0 ; int parens = 0 ; boolean inString = false ; do { char c = toParse . charAt ( idx ) ; if ( inString ) { if ( c == ' ' ) { if ( idx + 1 < toParse . length ( ) && toParse . charAt ( idx + 1 ) == ' ' ) { ++ idx ; // this is an escaped quote, skip it } else { inString = false ; if ( cbrackets == 0 && sbrackets == 0 && parens == 0 ) return idx + 1 ; } } // Skip any other character } else if ( c == ' ' ) { inString = true ; } else if ( c == ' ' ) { ++ cbrackets ; } else if ( c == ' ' ) { ++ sbrackets ; } else if ( c == ' ' ) { ++ parens ; } else if ( c == ' ' ) { if ( cbrackets == 0 ) return idx ; -- cbrackets ; if ( cbrackets == 0 && sbrackets == 0 && parens == 0 ) return idx + 1 ; } else if ( c == ' ' ) { if ( sbrackets == 0 ) return idx ; -- sbrackets ; if ( cbrackets == 0 && sbrackets == 0 && parens == 0 ) return idx + 1 ; } else if ( c == ' ' ) { if ( parens == 0 ) return idx ; -- parens ; if ( cbrackets == 0 && sbrackets == 0 && parens == 0 ) return idx + 1 ; } else if ( isBlank ( c ) || ! isCqlIdentifierChar ( c ) ) { if ( cbrackets == 0 && sbrackets == 0 && parens == 0 ) return idx ; } } while ( ++ idx < toParse . length ( ) ) ; if ( inString || cbrackets != 0 || sbrackets != 0 || parens != 0 ) throw new IllegalArgumentException ( ) ; return idx ; }
Assuming that idx points to the beginning of a CQL value in toParse returns the index of the first character after this value .