[pypy-svn] r12045 - in pypy/dist/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Sat May 7 01:24:17 CEST 2005
Author: arigo
Date: Sat May 7 01:24:17 2005
New Revision: 12045
Modified:
pypy/dist/pypy/objspace/std/stringobject.py
pypy/dist/pypy/objspace/std/test/test_stringobject.py
Log:
str.istitle() fix.
Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/stringobject.py Sat May 7 01:24:17 2005
@@ -131,18 +131,29 @@
return space.newbool(cased)
def str_istitle__String(space, w_self):
+ """Return True if S is a titlecased string and there is at least one
+character in S, i.e. uppercase characters may only follow uncased
+characters and lowercase characters only cased ones. Return False
+otherwise."""
input = w_self._value
- prev_letter='!'
+ cased = False
+ previous_is_cased = False
for pos in range(0, len(input)):
ch = input[pos]
- if _isalpha(ch):
- if (_isalpha(prev_letter) and _isupper(ch)) or \
- (not _isalpha(prev_letter) and _islower(ch)):
- return space.w_False
- prev_letter = ch
+ if _isupper(ch):
+ if previous_is_cased:
+ return space.w_False
+ previous_is_cased = True
+ cased = True
+ elif _islower(ch):
+ if not previous_is_cased:
+ return space.w_False
+ cased = True
+ else:
+ previous_is_cased = False
- return space.w_True
+ return space.newbool(cased)
def str_upper__String(space, w_self):
self = w_self._value
Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_stringobject.py Sat May 7 01:24:17 2005
@@ -152,6 +152,9 @@
assert "bro!wn fox".title() == "Bro!Wn Fox"
def test_istitle(self):
+ assert "".istitle() == False
+ assert "!".istitle() == False
+ assert "!!".istitle() == False
assert "brown fox".istitle() == False
assert "!brown fox".istitle() == False
assert "bROWN fOX".istitle() == False
More information about the Pypy-commit
mailing list