is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

R

rahul

is this generic API can be use to change ucs-2 to ucs-4
PyObject * PyCodec_Encode(
PyObject *object,
const char *encoding,
const char *errors
);

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be" for big endian system to set
ucs-4 encoding.
 
G

Gabriel Genellina

is this generic API can be use to change ucs-2 to ucs-4
PyObject * PyCodec_Encode(
PyObject *object,
const char *encoding,
const char *errors
);

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be" for big endian system to set
ucs-4 encoding.

The PyCodec_XXX functions seem to be undocumented - I don't know if this
is on purpose or not. Anyway, I'd use the str/unicode methods:

PyObject* u = PyString_AsDecodedObject(some_string_in_utf16, "utf-16",
NULL);
// don't forget to check for errors
PyObject* s = PyUnicode_AsEncodedString(u, "utf-32", NULL);
// don't forget to check for errors and decref u

Python 2.6 provides some convenience functions, like PyUnicode_DecodeUTF16
and PyUnicode_EncodeUTF32
 
G

Gabriel Genellina

is this generic API can be use to change ucs-2 to ucs-4

I forget to comment on UCS-2 and UCS-4. Python does not support them
directly; use utf-16 and utf-32 instead. If you start with an encoded
string in UCS-2, the differences are irrelevant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top