I need to convert python objects and strings from different encodings. Going from line c to a unicode object was pretty simple using PyUnicode_Decode, however I'm not sure how to go the other way.
//char* can be a wchar_t or any other element size, just make sure it is correctly terminated for its encoding Unicode(const char *str, size_t bytes, const char *encoding="utf-16", const char *errors="strict") :Object(PyUnicode_Decode(str, bytes, encoding, errors)) { //check for any python exceptions ExceptionCheck(); }
I want to create another function that takes a python unicode string and puts it in a buffer using the given encoding, for example:
//fills buffer with a null terminated string in encoding void AsCString(char *buffer, size_t bufferBytes, const char *encoding="utf-16", const char *errors="strict") { ... }
I suspect this is something related to PyUnicode_AsEncodedString, but returns PyObject, so I'm not sure how to put this in my buffer ...
Note. Both of the above methods are members of the C ++ Unicode class that wraps the python api. I am using Python 3.0
source share