mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
minor improvement, strip newlines from end of code snippets
This commit is contained in:
parent
1842b88c21
commit
084eb29d42
|
@ -117,10 +117,24 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
|
|||
text_filehandle.write('\n')
|
||||
|
||||
if (has_actual_code and not has_question_marks):
|
||||
linebuffer = clean_trailing_newlines(linebuffer)
|
||||
write_with_harness(codefile, sourcefile, start_linenum, linebuffer)
|
||||
return (line, linenum)
|
||||
|
||||
|
||||
def clean_trailing_newlines(linebuffer):
|
||||
result = []
|
||||
code_started = False
|
||||
linebuffer.reverse()
|
||||
for line in linebuffer:
|
||||
if not code_started and line == '\n':
|
||||
continue
|
||||
code_started = True
|
||||
result.append(line)
|
||||
result.reverse()
|
||||
return result
|
||||
|
||||
|
||||
def write_with_harness(codefile, sourcefile, start_linenum, linebuffer):
|
||||
'''write output with additional lines to make code likely compilable'''
|
||||
# add commonly used headers, so that lines can likely compile.
|
||||
|
|
Loading…
Reference in New Issue
Block a user