--- Objects/stringobject.c.orig Sat Dec 8 01:16:35 2001 +++ Objects/stringobject.c Sat Dec 8 18:48:09 2001 @@ -18,6 +18,17 @@ static PyStringObject *nullstring; #endif +#if defined(HAVE_MBTOWC) && defined(HAVE_WCHAR_H) +# define PRINT_MULTIBYTE_STRING +# include +# include +# if defined(HAVE_ISWPRINT) +# define _ISPRINT iswprint +# else +# define _ISPRINT isprint +# endif +#endif + /* PyString_FromStringAndSize() and PyString_FromString() try in certain cases to share string objects. When the size of the string is zero, these @@ -584,7 +595,12 @@ string_print(PyStringObject *op, FILE *fp, int flags) { int i; +#ifndef PRINT_MULTIBYTE_STRING char c; +#else + wchar_t c; + int cr; +#endif int quote; /* XXX Ought to check for interrupts when writing long strings */ @@ -610,7 +626,11 @@ fputc(quote, fp); for (i = 0; i < op->ob_size; i++) { +#ifndef PRINT_MULTIBYTE_STRING c = op->ob_sval[i]; +#else + cr = mbtowc(&c, op->ob_sval + i, op->ob_size - i); +#endif if (c == quote || c == '\\') fprintf(fp, "\\%c", c); else if (c == '\t') @@ -619,10 +639,17 @@ fprintf(fp, "\\n"); else if (c == '\r') fprintf(fp, "\\r"); - else if (c < ' ' || c >= 0x7f) - fprintf(fp, "\\x%02x", c & 0xff); - else +#ifndef PRINT_MULTIBYTE_STRING + else if (' ' <= c && c < 0x7f) fputc(c, fp); +#else + else if (_ISPRINT(c)) { + fwrite(op->ob_sval+i, cr, 1, fp); + i += cr - 1; + } +#endif + else + fprintf(fp, "\\x%02x", c & 0xff); } fputc(quote, fp); return 0;