[pypy-commit] pypy refactor-str-types: Implement title() method.

Manuel Jacob noreply at buildbot.pypy.org
Tue Jun 4 22:28:22 CEST 2013


Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r64784:8c06f1b5cde7
Date: 2013-06-04 21:34 +0200
http://bitbucket.org/pypy/pypy/changeset/8c06f1b5cde7/

Log:	Implement title() method.

diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -117,6 +117,8 @@
     def _isdigit(self, ch):
         return ch.isdigit()
 
+    _iscased = _isalpha
+
     def _upper(self, ch):
         if ch.islower():
             o = ord(ch) - 32
diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -776,22 +776,19 @@
         return space.wrap(builder.build())
 
     def descr_title(self, space):
-        # XXX just to pass the test
-        return space.wrap(self._val().title())
-
         selfval = self._val()
         if len(selfval) == 0:
             return self
 
         builder = self._builder(len(selfval))
-        prev_letter = ' '
-        for pos in range(len(input)):
-            ch = input[pos]
-            if not prev_letter.isalpha():
+        previous_is_cased = False
+        for pos in range(len(selfval)):
+            ch = selfval[pos]
+            if not previous_is_cased:
                 builder.append(self._upper(ch))
             else:
                 builder.append(self._lower(ch))
-            prev_letter = ch
+            previous_is_cased = self._iscased(ch)
         return space.wrap(builder.build())
 
     DEFAULT_NOOP_TABLE = ''.join([chr(i) for i in range(256)])
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -110,6 +110,9 @@
     def _isdigit(self, ch):
         return ch.isdigit()
 
+    def _iscased(self, ch):
+        return unicodedb.iscased(ord(ch))
+
     def _upper(self, ch):
         return unichr(unicodedb.toupper(ord(ch)))
 


More information about the pypy-commit mailing list