MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / ReverseCloseExpression

Function ReverseCloseExpression

rtpose_wrapper/scripts/cpp_lint.py:1327–1369  ·  view source on GitHub ↗

If input points to ) or } or ] or >, finds the position that opens it. If lines[linenum][pos] points to a ')' or '}' or ']' or '>', finds the linenum/pos that correspond to the opening of the expression. Args: clean_lines: A CleansedLines instance containing the file. linenum: The nu

(clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

1325
1326
1327def ReverseCloseExpression(clean_lines, linenum, pos):
1328 """If input points to ) or } or ] or >, finds the position that opens it.
1329
1330 If lines[linenum][pos] points to a ')' or '}' or ']' or '>', finds the
1331 linenum/pos that correspond to the opening of the expression.
1332
1333 Args:
1334 clean_lines: A CleansedLines instance containing the file.
1335 linenum: The number of the line to check.
1336 pos: A position on the line.
1337
1338 Returns:
1339 A tuple (line, linenum, pos) pointer *at* the opening brace, or
1340 (line, 0, -1) if we never find the matching opening brace. Note
1341 we ignore strings and comments when matching; and the line we
1342 return is the 'cleansed' line at linenum.
1343 """
1344 line = clean_lines.elided[linenum]
1345 endchar = line[pos]
1346 if endchar not in ')}]>':
1347 return (line, 0, -1)
1348 if endchar == ')': startchar = '('
1349 if endchar == ']': startchar = '['
1350 if endchar == '}': startchar = '{'
1351 if endchar == '>': startchar = '<'
1352
1353 # Check last line
1354 (start_pos, num_open) = FindStartOfExpressionInLine(
1355 line, pos, 0, startchar, endchar)
1356 if start_pos > -1:
1357 return (line, linenum, start_pos)
1358
1359 # Continue scanning backward
1360 while linenum > 0:
1361 linenum -= 1
1362 line = clean_lines.elided[linenum]
1363 (start_pos, num_open) = FindStartOfExpressionInLine(
1364 line, len(line) - 1, num_open, startchar, endchar)
1365 if start_pos > -1:
1366 return (line, linenum, start_pos)
1367
1368 # Did not find startchar before beginning of file, give up
1369 return (line, 0, -1)
1370
1371
1372def CheckForCopyright(filename, lines, error):

Callers 2

CheckBracesFunction · 0.85

Calls 1

Tested by

no test coverage detected