• Home
  • Raw
  • Download

Lines Matching +full:lines +full:- +full:and +full:- +full:columns

1 """Text wrapping and filling.
4 # Copyright (C) 1999-2001 Gregory P. Ward.
22 # 2.3, e.g. Optik and Docutils) by uncommenting the block of code below.
30 # Hardcode the recognized whitespace characters to the US-ASCII
32 # ISO-8859-1, 0xa0 is non-breaking whitespace, so in certain locales
36 # *non-breaking* space), 2) possibly cause problems with Unicode,
43 the wrap() and fill() methods; the other methods are just there for
50 the maximum width of wrapped lines (unless break_long_words
56 string that will be prepended to all lines save the first
64 after tab expansion. Note that if expand_tabs is false and
68 Ensure that sentence-ending punctuation is always followed
73 be broken, and some lines might be longer than 'width'.
76 preferably on whitespaces and right after hyphens part of
79 Drop leading and trailing whitespace from lines.
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
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
149 Munge whitespace in text: expand tabs and convert all other
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!'
197 and split() will convert that to [..., "foo.", " ", "Bar", ...]
203 while i < len(chunks)-1:
204 if chunks[i+1] == " " and patsearch(chunks[i]):
218 # Figure out when indent is larger than the specified width, and make
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 --
237 # If we're not allowed to break long words, and there's already
244 """_wrap_chunks(chunks : [string]) -> [string]
246 Wrap a sequence of text chunks and return a list of lines of
248 some lines may be longer than this.) Chunks correspond roughly
249 to words and the whitespace between them: each chunk is
253 Whitespace chunks will be removed from the beginning and end of
254 lines, but apart from that whitespace is preserved.
256 lines = []
272 if lines:
278 width = self.width - len(indent)
280 # First chunk on line is whitespace -- drop it, unless this
281 # is the very beginning of the text (ie. no lines started yet).
282 if self.drop_whitespace and chunks[-1].strip() == '' and lines:
283 del chunks[-1]
286 l = len(chunks[-1])
297 # The current line is full, and the next chunk is too big to
299 if chunks and len(chunks[-1]) > 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
307 # of all lines (return value).
309 lines.append(indent + ''.join(cur_line))
311 return lines
314 # -- Public interface ----------------------------------------------
317 """wrap(text : string) -> [string]
319 Reformat the single paragraph in 'text' so it fits in lines of
320 no more than 'self.width' columns, and return a list of wrapped
321 lines. Tabs in 'text' are expanded with string.expandtabs(),
322 and all other whitespace characters (including newline) are
332 """fill(text : string) -> string
334 Reformat the single paragraph in 'text' to fit in lines of no
335 more than 'self.width' columns, and return a new string
341 # -- Convenience interface ---------------------------------------------
344 """Wrap a single paragraph of text, returning a list of wrapped lines.
346 Reformat the single paragraph in 'text' so it fits in lines of no
347 more than 'width' columns, and return a list of wrapped lines. By
348 default, tabs in 'text' are expanded with string.expandtabs(), and
359 Reformat the single paragraph in 'text' to fit in lines of no more
360 than 'width' columns, and return a new string containing the entire
361 wrapped paragraph. As with wrap(), tabs are expanded and other
369 # -- Loosely related functionality -------------------------------------
377 This can be used to make triple-quoted strings line up with the left
381 Note that tabs and spaces are both treated as whitespace, but they
382 are not equal: the lines " hello" and "\\thello" are
387 # Look for the longest leading string of spaces and tabs common to
388 # all lines.
401 # Current line consistent with and no deeper than previous winner:
406 # Find the largest common whitespace between current line and previous
417 if 0 and margin: