[Python-checkins] python/dist/src/Objects unicodeobject.c,2.189,2.190

mhammond@users.sourceforge.net mhammond@users.sourceforge.net
2003年6月30日 17:13:30 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv6793
Modified Files:
	unicodeobject.c 
Log Message:
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
Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.189
retrieving revision 2.190
diff -C2 -d -r2.189 -r2.190
*** unicodeobject.c	28 Jun 2003 20:04:25 -0000	2.189
--- unicodeobject.c	1 Jul 2003 00:13:27 -0000	2.190
***************
*** 532,535 ****
--- 532,539 ----
 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);
***************
*** 592,595 ****
--- 596,603 ----
 	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);
***************
*** 2620,2623 ****
--- 2628,2642 ----
 }
 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);
 }
 

AltStyle によって変換されたページ (->オリジナル) /