question: public static int indexOfParenthesisMatch ( String str , int first ) throws URISyntaxException { int index = - 1 ; if ( first < 0 || first > str . length ( ) ) { throw new IllegalArgumentException ( "Invalid position for first parenthesis: " + first ) ; } if ( str . charAt ( first ) != '(' ) { throw new IllegalArgumentException ( "character at indicated position is not a parenthesis" ) ; } int depth = 1 ; char [ ] array = str . toCharArray ( ) ; for ( index = first + 1 ; index < array . length ; ++ index ) { char current = array [ index ] ; if ( current == '(' ) { depth ++ ; } else if ( current == ')' ) { if ( -- depth == 0 ) { break ; } } } if ( depth != 0 ) { throw new URISyntaxException ( str , "URI did not contain a matching parenthesis." ) ; } return index ; }
target:  Given a string and a position in that string of an open parend, find the matching close parend.