MCPcopy Create free account
hub / github.com/BVLC/caffe / ReverseCloseExpression

Function ReverseCloseExpression

scripts/cpp_lint.py:1331–1373  ·  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

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

Callers 2

CheckBracesFunction · 0.85

Calls 1

Tested by

no test coverage detected