Commit a91f0526 authored by Marius Wachtler's avatar Marius Wachtler

Add unichr()

parent 4480e933
...@@ -349,6 +349,16 @@ extern "C" Box* chr(Box* arg) { ...@@ -349,6 +349,16 @@ extern "C" Box* chr(Box* arg) {
return boxString(std::string(1, (char)n)); return boxString(std::string(1, (char)n));
} }
extern "C" Box* unichr(Box* arg) {
if (arg->cls != int_cls)
raiseExcHelper(TypeError, "an integer is required");
i64 n = static_cast<BoxedInt*>(arg)->n;
Box* rtn = PyUnicode_FromOrdinal(n);
checkAndThrowCAPIException();
return rtn;
}
extern "C" Box* ord(Box* obj) { extern "C" Box* ord(Box* obj) {
long ord; long ord;
Py_ssize_t size; Py_ssize_t size;
...@@ -1022,6 +1032,8 @@ void setupBuiltins() { ...@@ -1022,6 +1032,8 @@ void setupBuiltins() {
builtins_module->giveAttr("id", id_obj); builtins_module->giveAttr("id", id_obj);
chr_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)chr, STR, 1), "chr"); chr_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)chr, STR, 1), "chr");
builtins_module->giveAttr("chr", chr_obj); builtins_module->giveAttr("chr", chr_obj);
builtins_module->giveAttr("unichr",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)unichr, UNKNOWN, 1), "unichr"));
ord_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)ord, BOXED_INT, 1), "ord"); ord_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)ord, BOXED_INT, 1), "ord");
builtins_module->giveAttr("ord", ord_obj); builtins_module->giveAttr("ord", ord_obj);
trap_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)trap, UNKNOWN, 0), "trap"); trap_obj = new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)trap, UNKNOWN, 0), "trap");
......
...@@ -89,3 +89,5 @@ print "hello world".startswith(u'hello') ...@@ -89,3 +89,5 @@ print "hello world".startswith(u'hello')
print "hello world".startswith(u'world') print "hello world".startswith(u'world')
print float(u'1.0') print float(u'1.0')
print unichr(97)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment