MCPcopy Index your code
hub / github.com/cpplint/cpplint / FindEndOfExpressionInLine

Function FindEndOfExpressionInLine

cpplint.py:2195–2270  ·  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

(line, startpos, stack)

Source from the content-addressed store, hash-verified

2193
2194
2195def FindEndOfExpressionInLine(line, startpos, stack):
2196 """Find the position just after the end of current parenthesized expression.
2197
2198 Args:
2199 line: a CleansedLines line.
2200 startpos: start searching at this position.
2201 stack: nesting stack at startpos.
2202
2203 Returns:
2204 On finding matching end: (index just after matching end, None)
2205 On finding an unclosed expression: (-1, None)
2206 Otherwise: (-1, new stack at end of this line)
2207 """
2208 for i in range(startpos, len(line)):
2209 char = line[i]
2210 if char in "([{":
2211 # Found start of parenthesized expression, push to expression stack
2212 stack.append(char)
2213 elif char == "<":
2214 # Found potential start of template argument list
2215 if i > 0 and line[i - 1] == "<":
2216 # Left shift operator
2217 if stack and stack[-1] == "<":
2218 stack.pop()
2219 if not stack:
2220 return (-1, None)
2221 elif i > 0 and re.search(r"\boperator\s*$", line[0:i]):
2222 # operator<, don't add to stack
2223 continue
2224 else:
2225 # Tentative start of template argument list
2226 stack.append("<")
2227 elif char in ")]}":
2228 # Found end of parenthesized expression.
2229 #
2230 # If we are currently expecting a matching '>', the pending '<'
2231 # must have been an operator. Remove them from expression stack.
2232 while stack and stack[-1] == "<":
2233 stack.pop()
2234 if not stack:
2235 return (-1, None)
2236 if (
2237 (stack[-1] == "(" and char == ")")
2238 or (stack[-1] == "[" and char == "]")
2239 or (stack[-1] == "{" and char == "}")
2240 ):
2241 stack.pop()
2242 if not stack:
2243 return (i + 1, None)
2244 else:
2245 # Mismatched parentheses
2246 return (-1, None)
2247 elif char == ">":
2248 # Found potential end of template argument list.
2249
2250 # Ignore "->" and operator functions
2251 if i > 0 and (line[i - 1] == "-" or re.search(r"\boperator\s*$", line[0 : i - 1])):
2252 continue

Callers 2

CloseExpressionFunction · 0.85
CheckCheckFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected