• Home
  • Raw
  • Download

Lines Matching +full:check +full:- +full:whitespace

4 # Copyright (C) 1999-2001 Gregory P. Ward.
12 # Hardcode the recognized whitespace characters to the US-ASCII
13 # whitespace characters. The main reason for doing this is that
14 # some Unicode spaces (like \u00a0) are non-breaking whitespaces.
43 Replace all whitespace characters in the input text by spaces
48 Ensure that sentence-ending punctuation is always followed
59 Drop leading and trailing whitespace from 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!
76 whitespace = r'[%s]' % re.escape(_whitespace) variable in TextWrapper
77 nowhitespace = '[^' + whitespace[1:]
79 ( # any whitespace
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)
94 'ws': whitespace, 'nws': nowhitespace},
99 # "Hello there -- you goof-ball, use the -b option!"
101 # Hello/ /there/ /--/ /you/ /goof-ball,/ /use/ /the/ /-b/ /option!/
102 wordsep_simple_re = re.compile(r'(%s+)' % whitespace)
103 del whitespace
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
147 whitespace characters to spaces. Eg. " foo\\tbar\\n\\nbaz"
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!'
190 while i < len(chunks)-1:
202 Handle a chunk of text (most likely a word, not whitespace) that
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 --
239 """_wrap_chunks(chunks : [string]) -> [string]
244 to words and the whitespace between them: each chunk is
247 whitespace; ie. a chunk is either all whitespace or a "word".
248 Whitespace chunks will be removed from the beginning and end of
249 lines, but apart from that whitespace is preserved.
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])
301 if chunks and len(chunks[-1]) > width:
305 # If the last chunk on this line is all whitespace, drop it.
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]
322 if (cur_line[-1].strip() and
327 cur_len -= len(cur_line[-1])
328 del cur_line[-1]
331 prev_line = lines[-1].rstrip()
334 lines[-1] = prev_line + self.placeholder
345 # -- Public interface ----------------------------------------------
348 """wrap(text : string) -> [string]
353 and all other whitespace characters (including newline) are
362 """fill(text : string) -> string
371 # -- Convenience interface ---------------------------------------------
379 all other whitespace characters (including newline) are converted to
392 whitespace characters converted to space. See TextWrapper class for
401 The text first has its whitespace collapsed. If it then fits in
414 # -- Loosely related functionality -------------------------------------
420 """Remove any common leading whitespace from every line in `text`.
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
428 considered to have no common leading whitespace.
451 # Find the largest common whitespace between current line and previous
459 # sanity check (testing/debugging only)
475 it will default to adding 'prefix' to all non-empty lines that do not
476 consist solely of whitespace characters.