[pypy-commit] pypy unicode-utf8: use an actual iterator, to make the code nicer (they work well in rpython nowadays)
cfbolz
pypy.commits at gmail.com
Fri Nov 24 09:15:35 EST 2017
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: unicode-utf8
Changeset: r93162:6a13aba253bd
Date: 2017-11-24 15:07 +0100
http://bitbucket.org/pypy/pypy/changeset/6a13aba253bd/
Log: use an actual iterator, to make the code nicer (they work well in
rpython nowadays)
diff --git a/rpython/rlib/rutf8.py b/rpython/rlib/rutf8.py
--- a/rpython/rlib/rutf8.py
+++ b/rpython/rlib/rutf8.py
@@ -702,10 +702,12 @@
self._end = len(utf8s)
self._pos = 0
- def done(self):
- return self._pos == self._end
+ def __iter__(self):
+ return self
def next(self):
+ if self._pos == self._end:
+ raise StopIteration
ret = codepoint_at_pos(self._utf8, self._pos)
self._pos = next_codepoint_pos(self._utf8, self._pos)
return ret
diff --git a/rpython/rlib/test/test_rutf8.py b/rpython/rlib/test/test_rutf8.py
--- a/rpython/rlib/test/test_rutf8.py
+++ b/rpython/rlib/test/test_rutf8.py
@@ -188,6 +188,6 @@
def test_utf8_iterator(arg):
u = rutf8.Utf8StringIterator(arg.encode('utf8'))
l = []
- while not u.done():
- l.append(unichr(u.next()))
+ for c in u:
+ l.append(unichr(c))
assert list(arg) == l
More information about the pypy-commit
mailing list