File tree Expand file tree Collapse file tree 1 file changed +10
-29
lines changed
Expand file tree Collapse file tree 1 file changed +10
-29
lines changed Original file line number Diff line number Diff line change @@ -222,39 +222,20 @@ def c_repr(s: str) -> str:
222222
223223
224224def wrapped_c_string_literal (
225- line : str ,
225+ text : str ,
226+ * ,
226227 width : int = 72 ,
227- indent : int = 0 ,
228228 suffix : str = '' ,
229+ initial_indent : int = 0 ,
229230 subsequent_indent : int = 4
230231) -> str :
231- add , out = text_accumulator ()
232- words = line .split (' ' )
233- first = True
234- while True :
235- if first :
236- add (' ' * indent )
237- first = False
238- else :
239- add (' ' * subsequent_indent )
240- add ('"' )
241- sz = indent + 1
242- while True :
243- try :
244- word = words [0 ]
245- except IndexError :
246- add ('"' )
247- return out ()
248- sz += len (word ) + 1
249- if sz > width :
250- break
251- add (word )
252- del words [0 ]
253- if words :
254- add (' ' )
255- add ('"' )
256- add (suffix )
257- add ('\n ' )
232+ wrapped = textwrap .wrap (text , replace_whitespace = False ,
233+ drop_whitespace = False , break_on_hyphens = False )
234+ suffix = f"{ suffix } \n "
235+ lines = [f'"{ line } "{ suffix } ' for line in wrapped ]
236+ separator = subsequent_indent * ' '
237+ joined = initial_indent * ' ' + separator .join (lines )
238+ return joined .removesuffix (suffix )
258239
259240
260241is_legal_c_identifier = re .compile ('^[A-Za-z_][A-Za-z0-9_]*$' ).match
You can’t perform that action at this time.
0 commit comments