[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.98,2.99 unicodeobject.c,2.77,2.78

Ka-Ping Yee ping@users.sourceforge.net
Wed, 24 Jan 2001 09:19:10 -0800


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

Modified Files:
	stringobject.c unicodeobject.c 
Log Message:
Show '\011', '\012', and '\015' as '\t', '\n', '\r' in strings.
Switch from octal escapes to hex escapes for other nonprintable characters.


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.98
retrieving revision 2.99
diff -C2 -r2.98 -r2.99
*** stringobject.c	2001/01/19 03:03:47	2.98
--- stringobject.c	2001/01/24 17:19:08	2.99
***************
*** 336,341 ****
  		if (c == quote || c == '\\')
  			fprintf(fp, "\\%c", c);
! 		else if (c < ' ' || c >= 0177)
! 			fprintf(fp, "\\%03o", c & 0377);
  		else
  			fputc(c, fp);
--- 336,347 ----
  		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);
***************
*** 375,382 ****
  			if (c == quote || c == '\\')
  				*p++ = '\\', *p++ = c;
! 			else if (c < ' ' || c >= 0177) {
! 				sprintf(p, "\\%03o", c & 0377);
! 				while (*p != '\0')
! 					p++;
  			}
  			else
--- 381,393 ----
  			if (c == quote || c == '\\')
  				*p++ = '\\', *p++ = c;
! 			else if (c == '\t')
! 				*p++ = '\\', *p++ = 't';
! 			else if (c == '\n')
! 				*p++ = '\\', *p++ = 'n';
! 			else if (c == '\r')
! 				*p++ = '\\', *p++ = 'r';
! 			else if (c < ' ' || c >= 0x7f) {
! 				sprintf(p, "\\x%02x", c & 0xff);
!                                 p += 4;
  			}
  			else

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.77
retrieving revision 2.78
diff -C2 -r2.77 -r2.78
*** unicodeobject.c	2001/01/24 07:59:11	2.77
--- unicodeobject.c	2001/01/24 17:19:08	2.78
***************
*** 1344,1348 ****
      char *q;
  
!     static const char *hexdigit = "0123456789ABCDEF";
  
      repr = PyString_FromStringAndSize(NULL, 2 + 6*size + 1);
--- 1344,1348 ----
      char *q;
  
!     static const char *hexdigit = "0123456789abcdef";
  
      repr = PyString_FromStringAndSize(NULL, 2 + 6*size + 1);
***************
*** 1373,1382 ****
              *p++ = hexdigit[ch & 15];
          }
!         /* Map non-printable US ASCII to '\ooo' */
          else if (ch < ' ' || ch >= 128) {
              *p++ = '\\';
!             *p++ = hexdigit[(ch >> 6) & 7];
!             *p++ = hexdigit[(ch >> 3) & 7];
!             *p++ = hexdigit[ch & 7];
          } 
          /* Copy everything else as-is */
--- 1373,1395 ----
              *p++ = hexdigit[ch & 15];
          }
!         /* Map special whitespace to '\t', \n', '\r' */
!         else if (ch == '\t') {
!             *p++ = '\\';
!             *p++ = 't';
!         }
!         else if (ch == '\n') {
!             *p++ = '\\';
!             *p++ = 'n';
!         }
!         else if (ch == '\r') {
!             *p++ = '\\';
!             *p++ = 'r';
!         }
!         /* Map non-printable US ASCII to '\xhh' */
          else if (ch < ' ' || ch >= 128) {
              *p++ = '\\';
!             *p++ = 'x';
!             *p++ = hexdigit[(ch >> 4) & 0xf];
!             *p++ = hexdigit[ch & 15];
          } 
          /* Copy everything else as-is */
***************
*** 1499,1503 ****
      char *q;
  
!     static const char *hexdigit = "0123456789ABCDEF";
  
      repr = PyString_FromStringAndSize(NULL, 6 * size);
--- 1512,1516 ----
      char *q;
  
!     static const char *hexdigit = "0123456789abcdef";
  
      repr = PyString_FromStringAndSize(NULL, 6 * size);