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
5f512599
Commit
5f512599
authored
Jun 04, 2004
by
Hye-Shik Chang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add iswide() and width() method for UserString according as the
addition to unicode objects.
parent
0701bd64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
Lib/UserString.py
Lib/UserString.py
+4
-0
Lib/test/string_tests.py
Lib/test/string_tests.py
+25
-0
Lib/test/test_userstring.py
Lib/test/test_userstring.py
+2
-1
No files found.
Lib/UserString.py
View file @
5f512599
...
@@ -126,6 +126,10 @@ class UserString:
...
@@ -126,6 +126,10 @@ class UserString:
def
upper
(
self
):
return
self
.
__class__
(
self
.
data
.
upper
())
def
upper
(
self
):
return
self
.
__class__
(
self
.
data
.
upper
())
def
zfill
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
zfill
(
width
))
def
zfill
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
zfill
(
width
))
# the following methods are defined for unicode objects only:
def
iswide
(
self
):
return
self
.
data
.
iswide
()
def
width
(
self
):
return
self
.
data
.
width
()
class
MutableString
(
UserString
):
class
MutableString
(
UserString
):
"""mutable string objects
"""mutable string objects
...
...
Lib/test/string_tests.py
View file @
5f512599
...
@@ -695,3 +695,28 @@ class MixinStrUserStringTest:
...
@@ -695,3 +695,28 @@ class MixinStrUserStringTest:
self
.
checkraises
(
TypeError
,
'xyz'
,
'decode'
,
42
)
self
.
checkraises
(
TypeError
,
'xyz'
,
'decode'
,
42
)
self
.
checkraises
(
TypeError
,
'xyz'
,
'encode'
,
42
)
self
.
checkraises
(
TypeError
,
'xyz'
,
'encode'
,
42
)
class
MixinUnicodeUserStringTest
:
# Additional tests that only work with
# unicode compatible object, i.e. unicode and UserString
def
test_iswide
(
self
):
self
.
checkequal
(
False
,
u''
,
'iswide'
)
self
.
checkequal
(
False
,
u'
\
x1f
'
,
'iswide'
)
# Neutral
self
.
checkequal
(
False
,
u'
\
x20
'
,
'iswide'
)
# Narrow
self
.
checkequal
(
True
,
u'
\
u2329
'
,
'iswide'
)
# Wide
self
.
checkequal
(
False
,
u'
\
uff64
'
,
'iswide'
)
# Half
self
.
checkequal
(
True
,
u'
\
u3000
'
,
'iswide'
)
# Full
self
.
checkequal
(
False
,
u'
\
u2460
'
,
'iswide'
)
# Ambiguous
self
.
checkequal
(
True
,
u'
\
ud55c
\
uae00
'
,
'iswide'
)
self
.
checkequal
(
False
,
u'
\
ud55c
\
u2606
\
uae00
'
,
'iswide'
)
def
test_width
(
self
):
self
.
checkequal
(
0
,
u''
,
'width'
)
self
.
checkequal
(
4
,
u'abcd'
,
'width'
)
self
.
checkequal
(
2
,
u'
\
u0187
\
u01c9
'
,
'width'
)
self
.
checkequal
(
3
,
u'
\
u2460
\
u2329
'
,
'width'
)
self
.
checkequal
(
3
,
u'
\
u2329
\
u2460
'
,
'width'
)
self
.
checkequal
(
4
,
u'
\
ud55c
\
uae00
'
,
'width'
)
self
.
checkequal
(
5
,
u'
\
ud55c
\
u2606
\
uae00
'
,
'width'
)
Lib/test/test_userstring.py
View file @
5f512599
...
@@ -11,7 +11,8 @@ class UserStringTest(
...
@@ -11,7 +11,8 @@ class UserStringTest(
string_tests
.
CommonTest
,
string_tests
.
CommonTest
,
string_tests
.
MixinStrUnicodeUserStringTest
,
string_tests
.
MixinStrUnicodeUserStringTest
,
string_tests
.
MixinStrStringUserStringTest
,
string_tests
.
MixinStrStringUserStringTest
,
string_tests
.
MixinStrUserStringTest
string_tests
.
MixinStrUserStringTest
,
string_tests
.
MixinUnicodeUserStringTest
):
):
type2test
=
UserString
type2test
=
UserString
...
...
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