public static void FindMatchingBrace(Vector inputVec,IntPair curLoc,String errorMsg) throws ParseAlgorithmException {
  curLoc.two++;
  while (curLoc.one < inputVec.size()) {
    String curLine=(String)inputVec.elementAt(curLoc.one);
    while (curLoc.two < curLine.length()) {
      curLoc.two=NextBraceQuoteOrCommentCol(curLine,curLoc.two);
      if (curLoc.two < curLine.length()) {
        char c=curLine.charAt(curLoc.two);
        if (c == '}') {
          curLoc.two++;
          return;
        }
 else         if (c == '{') {
          FindMatchingBrace(inputVec,curLoc,errorMsg);
          curLine=(String)inputVec.elementAt(curLoc.one);
        }
 else         if ((c == '(') && (curLoc.two + 1 < curLine.length()) && (curLine.charAt(curLoc.two + 1) == '*')) {
          ParseAlgorithm.gotoEndOfComment(inputVec,curLoc);
          curLine=(String)inputVec.elementAt(curLoc.one);
        }
 else         if ((c == '\\') && (curLoc.two + 1 < curLine.length()) && (curLine.charAt(curLoc.two + 1) == '*')) {
          curLoc.two=curLine.length();
        }
 else         if (c == '"') {
          curLoc.two=ParseAlgorithm.findEndOfString(curLine,curLoc.two,curLoc.one);
        }
      }
    }
    curLoc.one++;
    curLoc.two=0;
  }
  throw new ParseAlgorithmException(errorMsg);
}

public static void FindMatchingBrace ( Vector inputVec , IntPair curLoc , String errorMsg ) throws ParseAlgorithmException { curLoc . two ++ ; while ( curLoc . one < inputVec . size ( ) ) { String curLine = ( String ) inputVec . elementAt ( curLoc . one ) ; while ( curLoc . two < curLine . length ( ) ) { curLoc . two = NextBraceQuoteOrCommentCol ( curLine , curLoc . two ) ; if ( curLoc . two < curLine . length ( ) ) { char c = curLine . charAt ( curLoc . two ) ; if ( c == '}' ) { curLoc . two ++ ; return ; } else if ( c == '{' ) { FindMatchingBrace ( inputVec , curLoc , errorMsg ) ; curLine = ( String ) inputVec . elementAt ( curLoc . one ) ; } else if ( ( c == '(' ) && ( curLoc . two + 1 < curLine . length ( ) ) && ( curLine . charAt ( curLoc . two + 1 ) == '*' ) ) { ParseAlgorithm . gotoEndOfComment ( inputVec , curLoc ) ; curLine = ( String ) inputVec . elementAt ( curLoc . one ) ; } else if ( ( c == '\\' ) && ( curLoc . two + 1 < curLine . length ( ) ) && ( curLine . charAt ( curLoc . two + 1 ) == '*' ) ) { curLoc . two = curLine . length ( ) ; } else if ( c == '"' ) { curLoc . two = ParseAlgorithm . findEndOfString ( curLine , curLoc . two , curLoc . one ) ; } } } curLoc . one ++ ; curLoc . two = 0 ; } throw new ParseAlgorithmException ( errorMsg ) ; }
assumes that curloc points to a left brace ( " { " ) in the string vector inputvec , and it searches for the matching right brace . it updates curloc to the position immediately after the token if it ' s found . otherwise , it raises a parsealgorithmexception . see the comments above for an explanation of the arguments . the pluscal code currently calls this only with replace = true and outputvec = null .
