c++ - embedded python passing unicode strings -


note works great if use ascii, but:

in utf8-encoded script have this:

print "frøânçïé" 

in embedded c++ have this:

pyobject*        cpython_script::print(pyobject *args) {         pyobject                *resultobjp        = null;         const char                *utf8_strz        = null;          if (pyarg_parsetuple(args, "s", &utf8_strz)) {                 log(utf8_strz, false);                  resultobjp = py_none;                 py_incref(resultobjp);         }          return resultobjp; } 

now, know log() can print utf8 (has years, debugged)

but actually prints this:

print "frøânçïé" fr√∏√¢n√ß√Ø√© 

another method use looks this: kj_commands.menu("控件", "同步滑帧", "全局无滑帧") or kj_commands.menu(u"控件", u"同步滑帧", u"全局无滑帧")

and in c++ have:

superstring                scpyobject::getas_string() {         superstring                str;          if (pyunicode_check(i_objp)) {                 #if 1                 //        method 1                 {                         scpyobject                utf8str(pyunicode_asutf8string(i_objp));                          str = utf8str.getas_string();                 }                 #elif 0                 //        method 2                 {                         utf8char                *uniz = (utf8char *)pyunicode_as_unicode(i_objp);                          str.assign(&uniz[0], &uniz[pyunicode_get_data_size(i_objp)], kcfstringencodingutf16);                 }                 #else                 //        method 3                 {                         utf32vec                        charvec(32768); cf_assert(sizeof(utf32vec::value_type) == sizeof(wchar_t));                         pyunicodeobject                *uniobjp = (pyunicodeobject *)(i_objp);                         py_ssize_t                        sizel(pyunicode_aswidechar(uniobjp, (wchar_t *)&charvec[0], charvec.size()));                          charvec.resize(sizel);                         charvec.push_back(0);                         str.set(superstring(&charvec[0]));                 }                 #endif         } else {                 str.set(uc(pystring_asstring(i_objp)));         }          log(str.utf8z());          return str; } 

for string, "控件", get: Êé߉ª∂

for unicode string, u"控件", methods 1, 2, , 3, same thing: Êé߉ª∂

okay doing wrong???


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -