[Python-checkins] python/dist/src/Objects stringobject.c,2.194,2.195

loewis@users.sourceforge.net loewis@users.sourceforge.net
Thu, 10 Oct 2002 22:38:02 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv30657/Objects

Modified Files:
	stringobject.c 
Log Message:
Back out #479898.


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.194
retrieving revision 2.195
diff -C2 -d -r2.194 -r2.195
*** stringobject.c	11 Oct 2002 00:43:48 -0000	2.194
--- stringobject.c	11 Oct 2002 05:37:59 -0000	2.195
***************
*** 27,44 ****
  
  
- #if defined(HAVE_MBTOWC) && defined(HAVE_WCHAR_H) && defined(HAVE_WCTYPE_H)
- #  define PRINT_MULTIBYTE_STRING
- #  include <locale.h>
- #  include <wchar.h>
- #  include <wctype.h>
- #  if defined(HAVE_ISWPRINT)
- #    define _isprint iswprint
- #  else
- #    define _isprint isprint
- #  endif
- #endif
- 
- static const char *hexchars = "0123456789abcdef";
- 
  /*
     For both PyString_FromString() and PyString_FromStringAndSize(), the
--- 27,30 ----
***************
*** 764,775 ****
  string_print(PyStringObject *op, FILE *fp, int flags)
  {
- #ifndef PRINT_MULTIBYTE_STRING
  	int i;
  	char c;
- #else
-         char *scur, *send;
- 	wchar_t c;
- 	int cr;
- #endif
  	int quote;
  
--- 750,755 ----
***************
*** 797,830 ****
  
  	fputc(quote, fp);
- #ifndef PRINT_MULTIBYTE_STRING
  	for (i = 0; i < op->ob_size; i++) {
  		c = op->ob_sval[i];
- #else
- 	for (scur = op->ob_sval, send = op->ob_sval + op->ob_size;
- 	     scur < send; scur += cr) {
- 		if ((cr = mbtowc(&c, scur, send - scur)) <= 0)
- 			goto non_printable;
- #endif
  		if (c == quote || c == '\\')
! 			fputc('\\', fp), fputc(c, fp);
                  else if (c == '\t')
!                         fputs("\\t", fp);
                  else if (c == '\n')
!                         fputs("\\n", fp);
                  else if (c == '\r')
!                         fputs("\\r", fp);
! #ifndef PRINT_MULTIBYTE_STRING
! 		else if (' ' <= c && c < 0x7f)
! 			fputc(c, fp);
  		else
!                         fprintf(fp, "\\x%02x", c & 0xff);
! #else
! 		else if (_isprint(c))
! 			fwrite(scur, cr, 1, fp);
! 		else {
! non_printable:		cr = 1; /* unit to move cursor */
!                         fprintf(fp, "\\x%02x", *scur & 0xff);
! 		}
! #endif
  	}
  	fputc(quote, fp);
--- 777,794 ----
  
  	fputc(quote, fp);
  	for (i = 0; i < op->ob_size; i++) {
  		c = op->ob_sval[i];
  		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 (c < ' ' || c >= 0x7f)
! 			fprintf(fp, "\\x%02x", c & 0xff);
  		else
! 			fputc(c, fp);
  	}
  	fputc(quote, fp);
***************
*** 847,858 ****
  	}
  	else {
- #ifndef PRINT_MULTIBYTE_STRING
  		register int i;
  		register char c;
- #else
- 		register char *scur, *send;
- 		wchar_t c;
- 		int cr;
- #endif
  		register char *p;
  		int quote;
--- 811,816 ----
***************
*** 867,871 ****
  		p = PyString_AS_STRING(v);
  		*p++ = quote;
- #ifndef PRINT_MULTIBYTE_STRING
  		for (i = 0; i < op->ob_size; i++) {
  			/* There's at least enough room for a hex escape
--- 825,828 ----
***************
*** 873,882 ****
  			assert(newsize - (p - PyString_AS_STRING(v)) >= 5);
  			c = op->ob_sval[i];
- #else
- 		for (scur = op->ob_sval, send = op->ob_sval + op->ob_size;
- 		     scur < send; scur += cr) {
- 			if ((cr = mbtowc(&c, scur, send - scur)) <= 0)
- 				goto non_printable;
- #endif
  			if (c == quote || c == '\\')
  				*p++ = '\\', *p++ = c;
--- 830,833 ----
***************
*** 887,904 ****
  			else if (c == '\r')
  				*p++ = '\\', *p++ = 'r';
! #ifndef PRINT_MULTIBYTE_STRING
! 			else if (' ' <= c && c < 0x7f)
! 				*p++ = c;
! 			else {
! #else
! 			else if (_isprint(c))
! 				memcpy(p, scur, cr), p += cr;
! 			else {
! non_printable:			cr = 1; c = *scur;
! #endif
! 				*p++ = '\\'; *p++ = 'x';
! 				*p++ = hexchars[(c >> 4) & 0x0f];
! 				*p++ = hexchars[c & 0x0f];
  			}
  		}
  		assert(newsize - (p - PyString_AS_STRING(v)) >= 1);
--- 838,850 ----
  			else if (c == '\r')
  				*p++ = '\\', *p++ = 'r';
! 			else if (c < ' ' || c >= 0x7f) {
! 				/* For performance, we don't want to call
! 				   PyOS_snprintf here (extra layers of
! 				   function call). */
! 				sprintf(p, "\\x%02x", c & 0xff);
!                                 p += 4;
  			}
+ 			else
+ 				*p++ = c;
  		}
  		assert(newsize - (p - PyString_AS_STRING(v)) >= 1);