Lines Matching +full:string +full:- +full:width
4 # Copyright (C) 1999-2001 Gregory P. Ward.
12 # Hardcode the recognized whitespace characters to the US-ASCII
14 # some Unicode spaces (like \u00a0) are non-breaking whitespaces.
26 width (default: 70)
27 the maximum width of wrapped lines (unless break_long_words
30 string that will be prepended to the first line of wrapped
31 output. Counts towards the line's width.
33 string that will be prepended to all lines save the first
34 of wrapped output; also counts towards each line's width.
48 Ensure that sentence-ending punctuation is always followed
52 Break words longer than 'width'. If false, those words will not
53 be broken, and some lines might be longer than 'width'.
69 # text up into word-wrappable chunks. E.g.
70 # "Hello there -- you goof-ball, use the -b option!"
72 # Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
81 | # em-dash between words
82 (?<=%(wp)s) -{2,} (?=\w)
86 -(?: (?<=%(lt)s{2}-) | (?<=%(lt)s-%(lt)s-))
87 (?= %(lt)s -? %(lt)s)
90 | # em-dash
91 (?<=%(wp)s) (?=-{2,}\w)
99 # "Hello there -- you goof-ball, use the -b option!"
101 # Hello/ /there/ /--/ /you/ /goof-ball,/ /use/ /the/ /-b/ /option!/
105 # XXX this is not locale- or charset-aware -- string.lowercase
106 # is US-ASCII only (and therefore English-only)
107 sentence_end_re = re.compile(r'[a-z]' # lowercase letter
108 r'[\.\!\?]' # sentence-ending punct.
109 r'[\"\']?' # optional end-of-quote
113 width=70, argument
126 self.width = width
140 # -- Private methods -----------------------------------------------
144 """_munge_whitespace(text : string) -> string
158 """_split(text : string) -> [string]
163 Look, goof-ball -- use the -b option!
165 'Look,', ' ', 'goof-', 'ball', ' ', '--', ' ',
166 'use', ' ', 'the', ' ', '-b', ' ', 'option!'
168 'Look,', ' ', 'goof-ball', ' ', '--', ' ',
169 'use', ' ', 'the', ' ', '-b', ' ', option!'
180 """_fix_sentence_endings(chunks : [string])
190 while i < len(chunks)-1:
197 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width): argument
198 """_handle_long_word(chunks : [string],
199 cur_line : [string],
200 cur_len : int, width : int)
205 # Figure out when indent is larger than the specified width, and make
207 if width < 1:
210 space_left = width - cur_len
216 chunk = reversed_chunks[-1]
219 # non-hyphens before it
220 hyphen = chunk.rfind('-', 0, space_left)
221 if hyphen > 0 and any(c != '-' for c in chunk[:hyphen]):
224 reversed_chunks[-1] = chunk[end:]
227 # it to the current line if there's nothing already there --
228 # that minimizes how much we violate the width constraint.
239 """_wrap_chunks(chunks : [string]) -> [string]
242 length 'self.width' or less. (If 'break_long_words' is false,
252 if self.width <= 0:
253 raise ValueError("invalid width %r (must be > 0)" % self.width)
259 if len(indent) + len(self.placeholder.lstrip()) > self.width:
260 raise ValueError("placeholder too large for max width")
273 # Figure out which static string will prefix this line.
279 # Maximum width for this line.
280 width = self.width - len(indent)
282 # First chunk on line is whitespace -- drop it, unless this
284 if self.drop_whitespace and chunks[-1].strip() == '' and lines:
285 del chunks[-1]
288 l = len(chunks[-1])
291 if cur_len + l <= width:
301 if chunks and len(chunks[-1]) > width:
302 self._handle_long_word(chunks, cur_line, cur_len, width)
306 if self.drop_whitespace and cur_line and cur_line[-1].strip() == '':
307 cur_len -= len(cur_line[-1])
308 del cur_line[-1]
316 not chunks[0].strip()) and cur_len <= width):
317 # Convert current line back to a string and store it in
322 if (cur_line[-1].strip() and
323 cur_len + len(self.placeholder) <= width):
327 cur_len -= len(cur_line[-1])
328 del cur_line[-1]
331 prev_line = lines[-1].rstrip()
333 self.width):
334 lines[-1] = prev_line + self.placeholder
345 # -- Public interface ----------------------------------------------
348 """wrap(text : string) -> [string]
351 no more than 'self.width' columns, and return a list of wrapped
352 lines. Tabs in 'text' are expanded with string.expandtabs(),
362 """fill(text : string) -> string
365 more than 'self.width' columns, and return a new string
371 # -- Convenience interface ---------------------------------------------
373 def wrap(text, width=70, **kwargs): argument
377 more than 'width' columns, and return a list of wrapped lines. By
378 default, tabs in 'text' are expanded with string.expandtabs(), and
383 w = TextWrapper(width=width, **kwargs)
386 def fill(text, width=70, **kwargs): argument
387 """Fill a single paragraph of text, returning a new string.
390 than 'width' columns, and return a new string containing the entire
395 w = TextWrapper(width=width, **kwargs)
398 def shorten(text, width, **kwargs): argument
399 """Collapse and truncate the given text to fit in the given width.
402 the *width*, it is returned as is. Otherwise, as many words
405 >>> textwrap.shorten("Hello world!", width=12)
407 >>> textwrap.shorten("Hello world!", width=11)
410 w = TextWrapper(width=width, max_lines=1, **kwargs)
414 # -- Loosely related functionality -------------------------------------
422 This can be used to make triple-quoted strings line up with the left
432 # Look for the longest leading string of spaces and tabs common to
475 it will default to adding 'prefix' to all non-empty lines that do not