def CloseExpression()

in cpplint.py [0:0]


def CloseExpression(clean_lines, linenum, pos):
    """If input points to ( or { or [ or <, finds the position that closes it.

  If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
  linenum/pos that correspond to the closing of the expression.

  TODO(unknown): cpplint spends a fair bit of time matching parentheses.
  Ideally we would want to index all opening and closing parentheses once
  and have CloseExpression be just a simple lookup, but due to preprocessor
  tricks, this is not so easy.

  Args:
    clean_lines: A CleansedLines instance containing the file.
    linenum: The number of the line to check.
    pos: A position on the line.

  Returns:
    A tuple (line, linenum, pos) pointer *past* the closing brace, or
    (line, len(lines), -1) if we never find a close.  Note we ignore
    strings and comments when matching; and the line we return is the
    'cleansed' line at linenum.
  """

    line = clean_lines.elided[linenum]
    if (line[pos] not in '({[<') or Match(r'<[<=]', line[pos:]):
        return (line, clean_lines.NumLines(), -1)

    # Check first line
    (end_pos, stack) = FindEndOfExpressionInLine(line, pos, [])
    if end_pos > -1:
        return (line, linenum, end_pos)

    # Continue scanning forward
    while stack and linenum < clean_lines.NumLines() - 1:
        linenum += 1
        line = clean_lines.elided[linenum]
        (end_pos, stack) = FindEndOfExpressionInLine(line, 0, stack)
        if end_pos > -1:
            return (line, linenum, end_pos)

    # Did not find end of expression before end of file, give up
    return (line, clean_lines.NumLines(), -1)