Commits

Benjamin Peterson committed e1c57be

add unichr (fixes #25)

  • Participants
  • Parent commits 9beb723

Comments (0)

Files changed (4)

 Development version
 -------------------
 
+- Issue #25: Add the unichr function, which returns a string for a Unicode
+  codepoint.
+
 - Issue #26: Add byte2int function which complements int2byte.
 
 - Add a PY2 constant with obvious semantics.

File documentation/index.rst

       ASCII data.
 
 
+.. function:: unichr(c)
+
+   Return the (Unicode) string representing the codepoint *c*.  This is
+   equivalent to :func:`py2:unichr` on Python 2 and :func:`py3:chr` on Python 3.
+
+
 .. function:: int2byte(i)
 
    Converts *i* to a byte.  *i* must be in ``range(0, 256)``.  This is
         return s.encode("latin-1")
     def u(s):
         return s
+    unichr = chr
     if sys.version_info[1] <= 1:
         def int2byte(i):
             return bytes((i,))
         return s
     def u(s):
         return unicode(s, "unicode_escape")
+    unichr = unichr
     int2byte = chr
     def byte2int(bs):
         return ord(bs[0])
     assert len(s) == 1
 
 
+def test_unichr():
+    assert six.u("\u1234") == six.unichr(0x1234)
+    assert type(six.u("\u1234")) is type(six.unichr(0x1234))
+
+
 def test_int2byte():
     assert six.int2byte(3) == six.b("\x03")
     py.test.raises((OverflowError, ValueError), six.int2byte, 256)