Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6186410d
Commit
6186410d
authored
Jun 03, 2004
by
Greg Ward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF #965425: fix so hyphenated words surrounded by punctuation are
wrapped correctly.
parent
29eb8c31
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
Lib/test/test_textwrap.py
Lib/test/test_textwrap.py
+18
-1
Lib/textwrap.py
Lib/textwrap.py
+3
-3
No files found.
Lib/test/test_textwrap.py
View file @
6186410d
#
# Test s
cript
for the textwrap module.
# Test s
uite
for the textwrap module.
#
# Original tests written by Greg Ward <gward@python.net>.
# Converted to PyUnit by Peter Hansen <peter@engcorp.com>.
...
...
@@ -271,6 +271,23 @@ What a mess!
self
.
check_split
(
"foo --option-opt bar"
,
[
"foo"
,
" "
,
"--option-"
,
"opt"
,
" "
,
"bar"
])
def
test_punct_hyphens
(
self
):
# Oh bother, SF #965425 found another problem with hyphens --
# hyphenated words in single quotes weren't handled correctly.
# In fact, the bug is that *any* punctuation around a hyphenated
# word was handled incorrectly, except for a leading "--", which
# was special-cased for Optik and Docutils. So test a variety
# of styles of punctuation around a hyphenated word.
# (Actually this is based on an Optik bug report, #813077).
self
.
check_split
(
"the 'wibble-wobble' widget"
,
[
'the'
,
' '
,
"'wibble-"
,
"wobble'"
,
' '
,
'widget'
])
self
.
check_split
(
'the "wibble-wobble" widget'
,
[
'the'
,
' '
,
'"wibble-'
,
'wobble"'
,
' '
,
'widget'
])
self
.
check_split
(
"the (wibble-wobble) widget"
,
[
'the'
,
' '
,
"(wibble-"
,
"wobble)"
,
' '
,
'widget'
])
self
.
check_split
(
"the ['wibble-wobble'] widget"
,
[
'the'
,
' '
,
"['wibble-"
,
"wobble']"
,
' '
,
'widget'
])
def
test_funky_parens
(
self
):
# Second part of SF bug #596434: long option strings inside
# parentheses.
...
...
Lib/textwrap.py
View file @
6186410d
...
...
@@ -79,11 +79,11 @@ class TextWrapper:
# Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
# (after stripping out empty strings).
wordsep_re
=
re
.
compile
(
r'(\
s+|
' # any whitespace
r'
-*
\
w
{
2
,}
-
(
?
=
\
w
{
2
,})
|
'
# hyphenated words
r'
[
^
\
s
\
w
]
*
\
w
{
2
,}
-
(
?
=
\
w
{
2
,})
|
'
# hyphenated words
r'
(
?
<=
[
\
w
\
!
\
"
\
'
\
&
\
.
\
,
\
?])-{2,}(?=
\
w))
'
) # em-dash
# XXX
will there be a locale-or-charset-aware version of
#
string.lowercase in 2.3?
# XXX
this is not locale- or charset-aware -- string.lowercase
#
is US-ASCII only (and therefore English-only)
sentence_end_re = re.compile(r'[%s]' # lowercase letter
r'[
\
.
\
!
\
?]
'
# sentence-ending punct.
r'[
\
"
\
'
]?' # optional end-of-quote
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment