diff options
author | fijal <unknown> | 2017-12-06 21:00:36 +0200 |
---|---|---|
committer | fijal <unknown> | 2017-12-06 21:00:36 +0200 |
commit | 147aca87fcd0647d53de891d0ee2af6466201a7c (patch) | |
tree | 31b04228e4896a76574c159d8b3d939f8635a821 /pypy/objspace/std/unicodeobject.py | |
parent | small improvements (diff) | |
download | pypy-147aca87fcd0647d53de891d0ee2af6466201a7c.tar.gz pypy-147aca87fcd0647d53de891d0ee2af6466201a7c.tar.bz2 pypy-147aca87fcd0647d53de891d0ee2af6466201a7c.zip |
more trivial use cases for Utf8StringIterator
Diffstat (limited to 'pypy/objspace/std/unicodeobject.py')
-rw-r--r-- | pypy/objspace/std/unicodeobject.py | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py index 93559ff8bd..aec7300e59 100644 --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -449,10 +449,7 @@ class W_UnicodeObject(W_Root): def _is_generic_loop(self, space, v, func_name): func = getattr(self, func_name) val = self._utf8 - i = 0 - while i < len(val): - uchar = rutf8.codepoint_at_pos(val, i) - i = rutf8.next_codepoint_pos(val, i) + for uchar in rutf8.Utf8StringIterator(val): if not func(uchar): return space.w_False return space.w_True @@ -535,11 +532,7 @@ class W_UnicodeObject(W_Root): def descr_istitle(self, space): cased = False previous_is_cased = False - val = self._utf8 - i = 0 - while i < len(val): - uchar = rutf8.codepoint_at_pos(val, i) - i = rutf8.next_codepoint_pos(val, i) + for uchar in rutf8.Utf8StringIterator(self._utf8): if unicodedb.isupper(uchar) or unicodedb.istitle(uchar): if previous_is_cased: return space.w_False @@ -555,16 +548,12 @@ class W_UnicodeObject(W_Root): def descr_isupper(self, space): cased = False - i = 0 - val = self._utf8 - while i < len(val): - uchar = rutf8.codepoint_at_pos(val, i) + for uchar in rutf8.Utf8StringIterator(self._utf8): if (unicodedb.islower(uchar) or unicodedb.istitle(uchar)): return space.w_False if not cased and unicodedb.isupper(uchar): cased = True - i = rutf8.next_codepoint_pos(val, i) return space.newbool(cased) def descr_startswith(self, space, w_prefix, w_start=None, w_end=None): |