[pypy-commit] pypy unicode-utf8: refactor

fijal pypy.commits at gmail.com
Wed Dec 6 14:40:58 EST 2017


Author: fijal
Branch: unicode-utf8
Changeset: r93290:c211485151ba
Date: 2017-12-06 21:40 +0200
http://bitbucket.org/pypy/pypy/changeset/c211485151ba/

Log:	refactor

diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -151,30 +151,30 @@
     res = StringBuilder(len(s))
     cur = 0
     iter = rutf8.Utf8StringIterator(s)
-    try:
-        while True:
+    while True:
+        try:
             ch = iter.next()
-            if ch <= 0xFF:
-                res.append(chr(ch))
-                cur += 1
-            else:
-                r, pos = errorhandler(errors, 'latin1',
-                                      'ordinal not in range(256)', s, cur,
-                                      cur + 1)
+        except StopIteration:
+            break
+        if ch <= 0xFF:
+            res.append(chr(ch))
+            cur += 1
+        else:
+            r, pos = errorhandler(errors, 'latin1',
+                                  'ordinal not in range(256)', s, cur,
+                                  cur + 1)
 
-                for c in rutf8.Utf8StringIterator(r):
-                    if c > 0xFF:
-                        errorhandler("strict", 'latin1',
-                                     'ordinal not in range(256)', s,
-                                     cur, cur + 1)
-                    res.append(chr(c))
+            for c in rutf8.Utf8StringIterator(r):
+                if c > 0xFF:
+                    errorhandler("strict", 'latin1',
+                                 'ordinal not in range(256)', s,
+                                 cur, cur + 1)
+                res.append(chr(c))
 
-                for j in range(pos - cur - 1):
-                    iter.next()
+            for j in range(pos - cur - 1):
+                iter.next()
 
-                cur = pos
-    except StopIteration:
-        pass
+            cur = pos
     r = res.build()
     return r
 


More information about the pypy-commit mailing list