MCPcopy Create free account
hub / github.com/apache/mesos / FindEndOfExpressionInLine

Function FindEndOfExpressionInLine

support/cpplint.py:1524–1599  ·  view source on GitHub ↗

Find the position just after the end of current parenthesized expression. Args: line: a CleansedLines line. startpos: start searching at this position. stack: nesting stack at startpos. Returns: On finding matching end: (index just after matching end, None) On finding an un

(line, startpos, stack)

Source from the content-addressed store, hash-verified

1522
1523
1524def FindEndOfExpressionInLine(line, startpos, stack):
1525 """Find the position just after the end of current parenthesized expression.
1526
1527 Args:
1528 line: a CleansedLines line.
1529 startpos: start searching at this position.
1530 stack: nesting stack at startpos.
1531
1532 Returns:
1533 On finding matching end: (index just after matching end, None)
1534 On finding an unclosed expression: (-1, None)
1535 Otherwise: (-1, new stack at end of this line)
1536 """
1537 for i in xrange(startpos, len(line)):
1538 char = line[i]
1539 if char in '([{':
1540 # Found start of parenthesized expression, push to expression stack
1541 stack.append(char)
1542 elif char == '<':
1543 # Found potential start of template argument list
1544 if i > 0 and line[i - 1] == '<':
1545 # Left shift operator
1546 if stack and stack[-1] == '<':
1547 stack.pop()
1548 if not stack:
1549 return (-1, None)
1550 elif i > 0 and Search(r'\boperator\s*$', line[0:i]):
1551 # operator<, don't add to stack
1552 continue
1553 else:
1554 # Tentative start of template argument list
1555 stack.append('<')
1556 elif char in ')]}':
1557 # Found end of parenthesized expression.
1558 #
1559 # If we are currently expecting a matching '>', the pending '<'
1560 # must have been an operator. Remove them from expression stack.
1561 while stack and stack[-1] == '<':
1562 stack.pop()
1563 if not stack:
1564 return (-1, None)
1565 if ((stack[-1] == '(' and char == ')') or
1566 (stack[-1] == '[' and char == ']') or
1567 (stack[-1] == '{' and char == '}')):
1568 stack.pop()
1569 if not stack:
1570 return (i + 1, None)
1571 else:
1572 # Mismatched parentheses
1573 return (-1, None)
1574 elif char == '>':
1575 # Found potential end of template argument list.
1576
1577 # Ignore "->" and operator functions
1578 if (i > 0 and
1579 (line[i - 1] == '-' or Search(r'\boperator\s*$', line[0:i - 1]))):
1580 continue
1581

Callers 2

CloseExpressionFunction · 0.85
CheckCheckFunction · 0.85

Calls 2

SearchFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected