Lines Matching +full:lines +full:- +full:and +full:- +full:columns
1 """Text wrapping and filling.
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.
20 the wrap() and fill() methods; the other methods are just there for
27 the maximum width of wrapped lines (unless break_long_words
33 string that will be prepended to all lines save the first
44 after tab expansion. Note that if expand_tabs is false and
48 Ensure that sentence-ending punctuation is always followed
53 be broken, and some lines might be longer than 'width'.
56 preferably on whitespaces and right after hyphens part of
59 Drop leading and trailing whitespace from lines.
61 Truncate wrapped lines.
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
140 # -- Private methods -----------------------------------------------
144 """_munge_whitespace(text : string) -> string
146 Munge whitespace in text: expand tabs and convert all other
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!'
184 and split() will convert that to [..., "foo.", " ", "Bar", ...]
190 while i < len(chunks)-1:
191 if chunks[i+1] == " " and patsearch(chunks[i]):
205 # Figure out when indent is larger than the specified width, and make
210 space_left = width - cur_len
216 chunk = reversed_chunks[-1]
217 if self.break_on_hyphens and len(chunk) > space_left:
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 --
232 # If we're not allowed to break long words, and there's already
239 """_wrap_chunks(chunks : [string]) -> [string]
241 Wrap a sequence of text chunks and return a list of lines of
243 some lines may be longer than this.) Chunks correspond roughly
244 to words and the whitespace between them: each chunk is
248 Whitespace chunks will be removed from the beginning and end of
249 lines, but apart from that whitespace is preserved.
251 lines = []
274 if lines:
280 width = self.width - len(indent)
282 # First chunk on line is whitespace -- drop it, unless this
283 # is the very beginning of the text (ie. no lines started yet).
284 if self.drop_whitespace and chunks[-1].strip() == '' and lines:
285 del chunks[-1]
288 l = len(chunks[-1])
299 # The current line is full, and the next chunk is too big to
301 if chunks and len(chunks[-1]) > 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]
312 len(lines) + 1 < self.max_lines or
314 self.drop_whitespace and
315 len(chunks) == 1 and
316 not chunks[0].strip()) and cur_len <= width):
317 # Convert current line back to a string and store it in
318 # list of all lines (return value).
319 lines.append(indent + ''.join(cur_line))
322 if (cur_line[-1].strip() and
325 lines.append(indent + ''.join(cur_line))
327 cur_len -= len(cur_line[-1])
328 del cur_line[-1]
330 if lines:
331 prev_line = lines[-1].rstrip()
334 lines[-1] = prev_line + self.placeholder
336 lines.append(indent + self.placeholder.lstrip())
339 return lines
345 # -- Public interface ----------------------------------------------
348 """wrap(text : string) -> [string]
350 Reformat the single paragraph in 'text' so it fits in lines of
351 no more than 'self.width' columns, and return a list of wrapped
352 lines. Tabs in 'text' are expanded with string.expandtabs(),
353 and all other whitespace characters (including newline) are
362 """fill(text : string) -> string
364 Reformat the single paragraph in 'text' to fit in lines of no
365 more than 'self.width' columns, and return a new string
371 # -- Convenience interface ---------------------------------------------
374 """Wrap a single paragraph of text, returning a list of wrapped lines.
376 Reformat the single paragraph in 'text' so it fits in lines of no
377 more than 'width' columns, and return a list of wrapped lines. By
378 default, tabs in 'text' are expanded with string.expandtabs(), and
389 Reformat the single paragraph in 'text' to fit in lines of no more
390 than 'width' columns, and return a new string containing the entire
391 wrapped paragraph. As with wrap(), tabs are expanded and other
399 """Collapse and truncate the given text to fit in the given width.
403 as possible are joined and then the placeholder is appended::
414 # -- Loosely related functionality -------------------------------------
422 This can be used to make triple-quoted strings line up with the left
426 Note that tabs and spaces are both treated as whitespace, but they
427 are not equal: the lines " hello" and "\\thello" are
430 Entirely blank lines are normalized to a newline character.
432 # Look for the longest leading string of spaces and tabs common to
433 # all lines.
446 # Current line consistent with and no deeper than previous winner:
451 # Find the largest common whitespace between current line and previous
460 if 0 and margin:
471 """Adds 'prefix' to the beginning of selected lines in 'text'.
473 If 'predicate' is provided, 'prefix' will only be added to the lines
475 it will default to adding 'prefix' to all non-empty lines that do not