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

Function CloseExpression

rtpose_wrapper/scripts/cpp_lint.py:1254–1297  ·  view source on GitHub ↗

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. Args: clean_lines: A CleansedLines instance containing the file. linenum: The n

(clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

1252
1253
1254def CloseExpression(clean_lines, linenum, pos):
1255 """If input points to ( or { or [ or <, finds the position that closes it.
1256
1257 If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
1258 linenum/pos that correspond to the closing of the expression.
1259
1260 Args:
1261 clean_lines: A CleansedLines instance containing the file.
1262 linenum: The number of the line to check.
1263 pos: A position on the line.
1264
1265 Returns:
1266 A tuple (line, linenum, pos) pointer *past* the closing brace, or
1267 (line, len(lines), -1) if we never find a close. Note we ignore
1268 strings and comments when matching; and the line we return is the
1269 'cleansed' line at linenum.
1270 """
1271
1272 line = clean_lines.elided[linenum]
1273 startchar = line[pos]
1274 if startchar not in '({[<':
1275 return (line, clean_lines.NumLines(), -1)
1276 if startchar == '(': endchar = ')'
1277 if startchar == '[': endchar = ']'
1278 if startchar == '{': endchar = '}'
1279 if startchar == '<': endchar = '>'
1280
1281 # Check first line
1282 (end_pos, num_open) = FindEndOfExpressionInLine(
1283 line, pos, 0, startchar, endchar)
1284 if end_pos > -1:
1285 return (line, linenum, end_pos)
1286
1287 # Continue scanning forward
1288 while linenum < clean_lines.NumLines() - 1:
1289 linenum += 1
1290 line = clean_lines.elided[linenum]
1291 (end_pos, num_open) = FindEndOfExpressionInLine(
1292 line, 0, num_open, startchar, endchar)
1293 if end_pos > -1:
1294 return (line, linenum, end_pos)
1295
1296 # Did not find endchar before end of file, give up
1297 return (line, clean_lines.NumLines(), -1)
1298
1299
1300def FindStartOfExpressionInLine(line, endpos, depth, startchar, endchar):

Callers 4

CheckSpacingFunction · 0.85
CheckBracesFunction · 0.85
CheckEmptyBlockBodyFunction · 0.85
CheckCheckFunction · 0.85

Calls 2

NumLinesMethod · 0.80

Tested by

no test coverage detected