X Tutup
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Compact version
  • Loading branch information
erlend-aasland committed Aug 7, 2023
commit 3de23788462dabdaa56af65d159f525fa6586df7
39 changes: 10 additions & 29 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,39 +222,20 @@ def c_repr(s: str) -> str:


def wrapped_c_string_literal(
line: str,
text: str,
*,
width: int = 72,
indent: int = 0,
suffix: str = '',
initial_indent: int = 0,
subsequent_indent: int = 4
Comment on lines +227 to +230
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems all call sites specify a value for the subsequent_indent parameter. Maybe it should be required, instead of optional?

Suggested change
width: int = 72,
suffix: str = '',
initial_indent: int = 0,
subsequent_indent: int = 4
subsequent_indent: int,
width: int = 72,
suffix: str = '',
initial_indent: int = 0,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, perhaps.

) -> str:
add, out = text_accumulator()
words = line.split(' ')
first = True
while True:
if first:
add(' ' * indent)
first = False
else:
add(' ' * subsequent_indent)
add('"')
sz = indent + 1
while True:
try:
word = words[0]
except IndexError:
add('"')
return out()
sz += len(word) + 1
if sz > width:
break
add(word)
del words[0]
if words:
add(' ')
add('"')
add(suffix)
add('\n')
wrapped = textwrap.wrap(text, replace_whitespace=False,
drop_whitespace=False, break_on_hyphens=False)
suffix = f"{suffix}\n"
lines = [f'"{line}"{suffix}' for line in wrapped]
separator = subsequent_indent * ' '
joined = initial_indent * ' ' + separator.join(lines)
return joined.removesuffix(suffix)


is_legal_c_identifier = re.compile('^[A-Za-z_][A-Za-z0-9_]*$').match
Expand Down
X Tutup