Lines Matching +full:string +full:- +full:width
4 # Copyright (C) 1999-2001 Gregory P. Ward.
10 import string, re
30 # Hardcode the recognized whitespace characters to the US-ASCII
32 # ISO-8859-1, 0xa0 is non-breaking whitespace, so in certain locales
33 # that character winds up in string.whitespace. Respecting
34 # string.whitespace in those cases would 1) make textwrap treat 0xa0 the
36 # *non-breaking* space), 2) possibly cause problems with Unicode,
49 width (default: 70)
50 the maximum width of wrapped lines (unless break_long_words
53 string that will be prepended to the first line of wrapped
54 output. Counts towards the line's width.
56 string that will be prepended to all lines save the first
57 of wrapped output; also counts towards each line's width.
68 Ensure that sentence-ending punctuation is always followed
72 Break words longer than 'width'. If false, those words will not
73 be broken, and some lines might be longer than 'width'.
82 whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
90 # text up into word-wrappable chunks. E.g.
91 # "Hello there -- you goof-ball, use the -b option!"
93 # Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
97 r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|' # hyphenated words
98 r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
101 # "Hello there -- you goof-ball, use the -b option!"
103 # Hello/ /there/ /--/ /you/ /goof-ball,/ /use/ /the/ /-b/ /option!/
106 # XXX this is not locale- or charset-aware -- string.lowercase
107 # is US-ASCII only (and therefore English-only)
109 r'[\.\!\?]' # sentence-ending punct.
110 r'[\"\']?' # optional end-of-quote
112 % string.lowercase)
116 width=70, argument
125 self.width = width
135 # recompile the regexes for Unicode mode -- done in this clumsy way for
136 # backwards compatibility because it's rather common to monkey-patch
143 # -- Private methods -----------------------------------------------
147 """_munge_whitespace(text : string) -> string
164 """_split(text : string) -> [string]
169 Look, goof-ball -- use the -b option!
171 'Look,', ' ', 'goof-', 'ball', ' ', '--', ' ',
172 'use', ' ', 'the', ' ', '-b', ' ', 'option!'
174 'Look,', ' ', 'goof-ball', ' ', '--', ' ',
175 'use', ' ', 'the', ' ', '-b', ' ', option!'
193 """_fix_sentence_endings(chunks : [string])
203 while i < len(chunks)-1:
210 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width): argument
211 """_handle_long_word(chunks : [string],
212 cur_line : [string],
213 cur_len : int, width : int)
218 # Figure out when indent is larger than the specified width, and make
220 if width < 1:
223 space_left = width - cur_len
228 cur_line.append(reversed_chunks[-1][:space_left])
229 reversed_chunks[-1] = reversed_chunks[-1][space_left:]
232 # it to the current line if there's nothing already there --
233 # that minimizes how much we violate the width constraint.
244 """_wrap_chunks(chunks : [string]) -> [string]
247 length 'self.width' or less. (If 'break_long_words' is false,
257 if self.width <= 0:
258 raise ValueError("invalid width %r (must be > 0)" % self.width)
271 # Figure out which static string will prefix this line.
277 # Maximum width for this line.
278 width = self.width - len(indent)
280 # First chunk on line is whitespace -- drop it, unless this
282 if self.drop_whitespace and chunks[-1].strip() == '' and lines:
283 del chunks[-1]
286 l = len(chunks[-1])
289 if cur_len + l <= width:
299 if chunks and len(chunks[-1]) > width:
300 self._handle_long_word(chunks, cur_line, cur_len, width)
303 if self.drop_whitespace and cur_line and cur_line[-1].strip() == '':
304 del cur_line[-1]
306 # Convert current line back to a string and store it in list
314 # -- Public interface ----------------------------------------------
317 """wrap(text : string) -> [string]
320 no more than 'self.width' columns, and return a list of wrapped
321 lines. Tabs in 'text' are expanded with string.expandtabs(),
332 """fill(text : string) -> string
335 more than 'self.width' columns, and return a new string
341 # -- Convenience interface ---------------------------------------------
343 def wrap(text, width=70, **kwargs): argument
347 more than 'width' columns, and return a list of wrapped lines. By
348 default, tabs in 'text' are expanded with string.expandtabs(), and
353 w = TextWrapper(width=width, **kwargs)
356 def fill(text, width=70, **kwargs): argument
357 """Fill a single paragraph of text, returning a new string.
360 than 'width' columns, and return a new string containing the entire
365 w = TextWrapper(width=width, **kwargs)
369 # -- Loosely related functionality -------------------------------------
377 This can be used to make triple-quoted strings line up with the left
387 # Look for the longest leading string of spaces and tabs common to