[Python-checkins] python/dist/src/Lib textwrap.py,1.2,1.3
gward@users.sourceforge.net
gward@users.sourceforge.net
Fri, 07 Jun 2002 15:04:17 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv8618
Modified Files:
textwrap.py
Log Message:
Convert _fix_sentence_endings() to use a regex, and augment it to
handle sentences like this:
And she said, "Go to hell!" Can you believe that?
Index: textwrap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/textwrap.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** textwrap.py 7 Jun 2002 21:56:16 -0000 1.2
--- textwrap.py 7 Jun 2002 22:04:15 -0000 1.3
***************
*** 55,60 ****
r'(?<=\w)-{2,}(?=\w))') # em-dash
! # Punctuation characters found at the end of a sentence.
! sentence_end = ".?!"
--- 55,64 ----
r'(?<=\w)-{2,}(?=\w))') # em-dash
! # XXX will there be a locale-or-charset-aware version of
! # string.lowercase in 2.3?
! sentence_end_re = re.compile(r'[%s]' # lowercase letter
! r'[\.\!\?]' # sentence-ending punct.
! r'[\"\']?' # optional end-of-quote
! % string.lowercase)
***************
*** 108,118 ****
"""
i = 0
! punct = self.sentence_end
while i < len(chunks)-1:
! # chunks[i] looks like the last word of a sentence,
! # and it's followed by a single space.
! if (chunks[i][-1] in punct and
! chunks[i+1] == " " and
! islower(chunks[i][-2])):
chunks[i+1] = " "
i += 2
--- 112,118 ----
"""
i = 0
! pat = self.sentence_end_re
while i < len(chunks)-1:
! if chunks[i+1] == " " and pat.search(chunks[i]):
chunks[i+1] = " "
i += 2