Skip to content

Commit bf6748b

Browse files
author
thk123
committed
Add a method that concatenates section of the code
Starting at elided_lines[start_line][linepos] take the end of the line until the ending line.
1 parent 8fbb094 commit bf6748b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scripts/cpplint.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import string
5353
import sys
5454
import unicodedata
55+
import itertools
5556

5657

5758
_USAGE = """
@@ -6121,6 +6122,32 @@ def CheckMakePairUsesDeduction(filename, clean_lines, linenum, error):
61216122
'For C++11-compatibility, omit template arguments from make_pair'
61226123
' OR use pair directly OR if appropriate, construct a pair directly')
61236124

6125+
def AssembleString(clean_lines, start_lineno, start_linepos, end_lineno, end_linepos):
6126+
"""
6127+
Concatenates all the strings between the starting line position and
6128+
the ending line position.
6129+
6130+
Note: this operated on the elided (no strings and comments) view of the
6131+
code.
6132+
6133+
Args:
6134+
clean_lines: All the lines
6135+
start_lineno: The starting line number
6136+
start_linepos: The index of the first character to include
6137+
end_lineno: The last line
6138+
end_linepos: The index of the first character not to include
6139+
"""
6140+
if end_lineno < start_lineno:
6141+
return ''
6142+
6143+
if start_lineno == end_lineno:
6144+
return clean_lines.elided[start_lineno][start_linepos : end_linepos]
6145+
6146+
full_string = clean_lines.elided[start_lineno][start_linepos:]
6147+
for line in itertools.islice(clean_lines.elided, start_lineno + 1, end_lineno):
6148+
full_string += line
6149+
full_string += clean_lines.elided[end_lineno][:end_linepos]
6150+
return full_string
61246151

61256152
def CheckRedundantVirtual(filename, clean_lines, linenum, error):
61266153
"""Check if line contains a redundant "virtual" function-specifier.

0 commit comments

Comments
 (0)