Find position at the matching startchar. This is almost the reverse of FindEndOfExpressionInLine, but note that the input position and returned position differs by 1. Args: line: a CleansedLines line. endpos: start searching at this position. depth: nesting level at endpos. s
(line, endpos, depth, startchar, endchar)
| 1302 | |
| 1303 | |
| 1304 | def FindStartOfExpressionInLine(line, endpos, depth, startchar, endchar): |
| 1305 | """Find position at the matching startchar. |
| 1306 | |
| 1307 | This is almost the reverse of FindEndOfExpressionInLine, but note |
| 1308 | that the input position and returned position differs by 1. |
| 1309 | |
| 1310 | Args: |
| 1311 | line: a CleansedLines line. |
| 1312 | endpos: start searching at this position. |
| 1313 | depth: nesting level at endpos. |
| 1314 | startchar: expression opening character. |
| 1315 | endchar: expression closing character. |
| 1316 | |
| 1317 | Returns: |
| 1318 | On finding matching startchar: (index at matching startchar, 0) |
| 1319 | Otherwise: (-1, new depth at beginning of this line) |
| 1320 | """ |
| 1321 | for i in xrange(endpos, -1, -1): |
| 1322 | if line[i] == endchar: |
| 1323 | depth += 1 |
| 1324 | elif line[i] == startchar: |
| 1325 | depth -= 1 |
| 1326 | if depth == 0: |
| 1327 | return (i, 0) |
| 1328 | return (-1, depth) |
| 1329 | |
| 1330 | |
| 1331 | def ReverseCloseExpression(clean_lines, linenum, pos): |
no outgoing calls
no test coverage detected