diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2003-07-01 00:13:27 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2003-07-01 00:13:27 (GMT) |
commit | 0ccda1ee1096799a30a6480feab0f6032f707c01 (patch) | |
tree | 9695feb839fc158b68d4c61574080cd8cdc96c58 /Objects | |
parent | ecc7171007e692b8444c084f6f32be550dddc628 (diff) | |
download | cpython-0ccda1ee1096799a30a6480feab0f6032f707c01.zip cpython-0ccda1ee1096799a30a6480feab0f6032f707c01.tar.gz cpython-0ccda1ee1096799a30a6480feab0f6032f707c01.tar.bz2 |
Support 'mbcs' as a 'built-in' encoding, so the C API can use it without
defering to the encodings package.
As described in [ 763111 ] mbcs encoding should skip encodings package
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index af427dd..b165597 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -531,6 +531,10 @@ PyObject *PyUnicode_Decode(const char *s, return PyUnicode_DecodeUTF8(s, size, errors); else if (strcmp(encoding, "latin-1") == 0) return PyUnicode_DecodeLatin1(s, size, errors); +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) + else if (strcmp(encoding, "mbcs") == 0) + return PyUnicode_DecodeMBCS(s, size, errors); +#endif else if (strcmp(encoding, "ascii") == 0) return PyUnicode_DecodeASCII(s, size, errors); @@ -591,6 +595,10 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode, return PyUnicode_AsUTF8String(unicode); else if (strcmp(encoding, "latin-1") == 0) return PyUnicode_AsLatin1String(unicode); +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) + else if (strcmp(encoding, "mbcs") == 0) + return PyUnicode_AsMBCSString(unicode); +#endif else if (strcmp(encoding, "ascii") == 0) return PyUnicode_AsASCIIString(unicode); } @@ -2621,6 +2629,17 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p, return repr; } +PyObject *PyUnicode_AsMBCSString(PyObject *unicode) +{ + if (!PyUnicode_Check(unicode)) { + PyErr_BadArgument(); + return NULL; + } + return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode), + PyUnicode_GET_SIZE(unicode), + NULL); +} + #endif /* MS_WINDOWS */ /* --- Character Mapping Codec -------------------------------------------- */ |