diff options
| author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-27 00:25:46 +0000 | 
|---|---|---|
| committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-27 00:25:46 +0000 | 
| commit | ad158728549b7161f08ecdf74ac14a0f9eff3160 (patch) | |
| tree | 4cd9eeae2e28f0610da74077e343d894ccba556d /Objects/unicodeobject.c | |
| parent | 91b47c64e1ca8323f01633c0e890c9d6bc3f605e (diff) | |
| download | cpython-git-ad158728549b7161f08ecdf74ac14a0f9eff3160.tar.gz | |
Simplify PyUnicode_Encode/DecodeFSDefault on Windows/Mac OS X
 * Windows always uses mbcs
 * Mac OS X always uses utf-8
Diffstat (limited to 'Objects/unicodeobject.c')
| -rw-r--r-- | Objects/unicodeobject.c | 34 | 
1 files changed, 18 insertions, 16 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index f5c09dd7f8..17dc27e6e9 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1584,15 +1584,19 @@ PyObject *PyUnicode_AsEncodedObject(PyObject *unicode,      return NULL;  } -PyObject *PyUnicode_EncodeFSDefault(PyObject *unicode) +PyObject * +PyUnicode_EncodeFSDefault(PyObject *unicode)  { -    if (Py_FileSystemDefaultEncoding) {  #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) -        if (strcmp(Py_FileSystemDefaultEncoding, "mbcs") == 0) -            return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode), -                                        PyUnicode_GET_SIZE(unicode), -                                        NULL); -#endif +    return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode), +                                PyUnicode_GET_SIZE(unicode), +                                NULL); +#elif defined(__APPLE__) +    return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode), +                                PyUnicode_GET_SIZE(unicode), +                                "surrogateescape"); +#else +    if (Py_FileSystemDefaultEncoding) {          return PyUnicode_AsEncodedString(unicode,                                           Py_FileSystemDefaultEncoding,                                           "surrogateescape"); @@ -1615,6 +1619,7 @@ PyObject *PyUnicode_EncodeFSDefault(PyObject *unicode)          PyMem_Free(bytes);          return bytes_obj;      } +#endif  }  PyObject *PyUnicode_AsEncodedString(PyObject *unicode, @@ -1761,21 +1766,17 @@ PyUnicode_DecodeFSDefault(const char *s) {  PyObject*  PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)  { +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) +    return PyUnicode_DecodeMBCS(s, size, NULL); +#elif defined(__APPLE__) +    return PyUnicode_DecodeUTF8(s, size, "surrogateescape"); +#else      /* During the early bootstrapping process, Py_FileSystemDefaultEncoding         can be undefined. If it is case, decode using UTF-8. The following assumes         that Py_FileSystemDefaultEncoding is set to a built-in encoding during the         bootstrapping process where the codecs aren't ready yet.      */      if (Py_FileSystemDefaultEncoding) { -#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) -        if (strcmp(Py_FileSystemDefaultEncoding, "mbcs") == 0) { -            return PyUnicode_DecodeMBCS(s, size, NULL); -        } -#elif defined(__APPLE__) -        if (strcmp(Py_FileSystemDefaultEncoding, "utf-8") == 0) { -            return PyUnicode_DecodeUTF8(s, size, "surrogateescape"); -        } -#endif          return PyUnicode_Decode(s, size,                                  Py_FileSystemDefaultEncoding,                                  "surrogateescape"); @@ -1799,6 +1800,7 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)          PyMem_Free(wchar);          return unicode;      } +#endif  }  | 
