--- stringobject.c.orig Fri Nov 9 13:33:26 2001 +++ stringobject.c Fri Nov 9 16:00:31 2001 @@ -1,9 +1,13 @@ +#define PRINT_MULTIBYTE_STRING /* String object implementation */ #include "Python.h" #include +#ifdef PRINT_MULTIBYTE_STRING +#include +#endif #ifdef COUNT_ALLOCS int null_strings, one_strings; @@ -564,8 +568,13 @@ string_print(PyStringObject *op, FILE *fp, int flags) { int i; - char c; int quote; +#ifndef PRINT_MULTIBYTE_STRING + char c; +#else + wchar_t c; + int cvres; +#endif /* XXX Ought to check for interrupts when writing long strings */ if (! PyString_CheckExact(op)) { @@ -589,6 +598,7 @@ quote = '"'; fputc(quote, fp); +#ifndef PRINT_MULTIBYTE_STRING for (i = 0; i < op->ob_size; i++) { c = op->ob_sval[i]; if (c == quote || c == '\\') @@ -604,6 +614,33 @@ else fputc(c, fp); } +#else + for (i = 0; i < op->ob_size; i++) { + cvres = mbtowc(&c, op->ob_sval + i, op->ob_size - i); + if (cvres > 0) { + if (c == quote || c == '\\') + fprintf(fp, "\\%c", c); + else if (c == '\t') + fprintf(fp, "\\t"); + else if (c == '\n') + fprintf(fp, "\\n"); + else if (c == '\r') + fprintf(fp, "\\r"); + else if (isprint(c)) { + for (; cvres; cvres--) + fputc(op->ob_sval[i++], fp); + i--; + } else { +invalid_char: for (; cvres; cvres--) + fprintf(fp, "\\x%02x", op->ob_sval[i++] & 0xff); + i--; + } + } else if (cvres <= 0) { + cvres = 1; + goto invalid_char; + } + } +#endif fputc(quote, fp); return 0; }