Lichen

Changeset

472:3a12bbe87788
2017-01-15 Paul Boddie raw files shortlog changelog graph Make string representations of integers Unicode objects having an implicit UTF-8 encoding, thus permitting them to be combined successfully with other Unicode objects.
lib/__builtins__/int.py (file) tests/numbers.py (file)
     1.1 --- a/lib/__builtins__/int.py	Sun Jan 15 16:18:03 2017 +0100
     1.2 +++ b/lib/__builtins__/int.py	Sun Jan 15 18:10:54 2017 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  """
     1.5  
     1.6  from __builtins__.operator import _negate
     1.7 +from __builtins__.unicode import utf8string
     1.8  from native import isinstance as _isinstance, get_maxint, get_minint, \
     1.9                     int_add, int_and, int_div, int_eq, int_gt, int_lt, int_mod, \
    1.10                     int_mul, int_ne, int_neg, int_not, int_or, int_pow, \
    1.11 @@ -217,7 +218,7 @@
    1.12  
    1.13          "Return a string representation."
    1.14  
    1.15 -        return int_str(self.__data__)
    1.16 +        return utf8string(int_str(self.__data__))
    1.17  
    1.18      __repr__ = __str__
    1.19  
     2.1 --- a/tests/numbers.py	Sun Jan 15 16:18:03 2017 +0100
     2.2 +++ b/tests/numbers.py	Sun Jan 15 18:10:54 2017 +0100
     2.3 @@ -1,3 +1,5 @@
     2.4 +# -*- coding: ISO-8859-1 -*-
     2.5 +
     2.6  import sys
     2.7  
     2.8  print "# sys.maxint: ",
     2.9 @@ -52,3 +54,15 @@
    2.10  
    2.11  print "# hash((sys.maxint - 1, 0)): ",
    2.12  print hash((sys.maxint - 1, 0))
    2.13 +
    2.14 +# Test combining numbers with strings.
    2.15 +
    2.16 +s = "Number is " + str(123)
    2.17 +s2 = "זרו -> " + str(123)
    2.18 +print s.__class__
    2.19 +print s2.__class__
    2.20 +print s
    2.21 +print s2
    2.22 +
    2.23 +sys.stdout.encoding = "UTF-8"
    2.24 +print s2