Skip to content

Commit a10b42d

Browse files
committed
builtin: fix hex formating
1 parent 587ae18 commit a10b42d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

‎builtin/builtin.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package builtin
77

88
import (
99
"bytes"
10+
"fmt"
1011
"strconv"
1112
"unicode"
1213
"unicode/utf8"
@@ -333,9 +334,12 @@ func builtin_ascii(self, o py.Object) (py.Object, error){
333334
for_, c:=rangerepr{
334335
ifc<=unicode.MaxASCII{
335336
sb.WriteRune(c)
336-
} else{
337+
} elseifc<0x10000{
337338
s:="\\u"+strconv.FormatInt(int64(c), 16)
338339
sb.WriteString(s)
340+
} else{
341+
s:=fmt.Sprintf("\\U%08x", c)
342+
sb.WriteString(s)
339343
}
340344
}
341345

‎builtin/tests/builtin.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def __repr__(self):
3030
assertascii('\t\r\n') =="'\\t\\r\\n'"
3131
assertascii("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F") =="'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f'"
3232
assertascii(B()) =='repr method'
33+
assertascii(chr(0x100)) =="'\\u100'"
34+
assertascii(chr(0x1001)) =="'\\u1001'"
35+
assertascii(chr(0x10001)) =="'\\U00010001'"
3336

3437
doc="chr"
3538
assertchr(65) =="A"

0 commit comments

Comments
(0)