summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-03-28 02:01:52 (GMT)
committerGuido van Rossum <guido@python.org>2000-03-28 02:01:52 (GMT)
commitb7a40ba8d3f520ed49a0018272bf25ee67274fca (patch)
tree496c6485e0aeb30bedd2f41bbe279ffff3c7a995 /Objects
parentefec1158c1a5cbd4a1b9679fc218915676f69dd0 (diff)
downloadcpython-b7a40ba8d3f520ed49a0018272bf25ee67274fca.zip
cpython-b7a40ba8d3f520ed49a0018272bf25ee67274fca.tar.gz
cpython-b7a40ba8d3f520ed49a0018272bf25ee67274fca.tar.bz2
MBCS codecs. (Win32 only.) By Mark Hammond.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index d63165e..8c1db7e 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -73,6 +73,9 @@ Unicode Integration Proposal (see file Misc/unicode.txt).
#define INT_MAX 2147483647
#endif
+#ifdef MS_WIN32
+#include <windows.h>
+#endif
/* Limit for the Unicode object free list */
#define MAX_UNICODE_FREELIST_SIZE 1024
@@ -1479,6 +1482,62 @@ PyObject *PyUnicode_AsASCIIString(PyObject *unicode)
NULL);
}
+#ifdef MS_WIN32
+/* --- MBCS codecs for Windows -------------------------------------------- */
+PyObject *PyUnicode_DecodeMBCS(const char *s,
+ int size,
+ const char *errors)
+{
+ PyUnicodeObject *v;
+ Py_UNICODE *p;
+
+ /* First get the size of the result */
+ DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL, 0);
+ if (usize==0)
+ return PyErr_SetFromWindowsErrWithFilename(0, NULL);
+
+ v = _PyUnicode_New(usize);
+ if (v == NULL)
+ return NULL;
+ if (usize == 0)
+ return (PyObject *)v;
+ p = PyUnicode_AS_UNICODE(v);
+ if (0 == MultiByteToWideChar(CP_ACP, 0, s, size, p, usize)) {
+ Py_DECREF(v);
+ return PyErr_SetFromWindowsErrWithFilename(0, NULL);
+ }
+
+ return (PyObject *)v;
+}
+
+PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
+ int size,
+ const char *errors)
+{
+ PyObject *repr;
+ char *s;
+
+ /* First get the size of the result */
+ DWORD mbcssize = WideCharToMultiByte(CP_ACP, 0, p, size, NULL, 0, NULL, NULL);
+ if (mbcssize==0)
+ return PyErr_SetFromWindowsErrWithFilename(0, NULL);
+
+ repr = PyString_FromStringAndSize(NULL, mbcssize);
+ if (repr == NULL)
+ return NULL;
+ if (mbcssize==0)
+ return repr;
+
+ /* Do the conversion */
+ s = PyString_AS_STRING(repr);
+ if (0 == WideCharToMultiByte(CP_ACP, 0, p, size, s, mbcssize, NULL, NULL)) {
+ Py_DECREF(repr);
+ return PyErr_SetFromWindowsErrWithFilename(0, NULL);
+ }
+ return repr;
+}
+#endif /* MS_WIN32 */
+
/* --- Character Mapping Codec -------------------------------------------- */
static