Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 16226:c7c404b35f33 legacy-trunk
Show '\011', '\012', and '\015' as '\t', '\n', '\r' in strings.
Switch from octal escapes to hex escapes for other nonprintable characters.
| author | Ka-Ping Yee <ping@zesty.ca> |
|---|---|
| date | Wed, 24 Jan 2001 17:19:08 +0000 |
| parents | 754ecd21fbef |
| children | ca1be7d00413 |
line wrap: on
line diff
--- a/Objects/stringobject.c Wed Jan 24 17:18:21 2001 +0000 +++ b/Objects/stringobject.c Wed Jan 24 17:19:08 2001 +0000 @@ -335,8 +335,14 @@ c = op->ob_sval[i]; if (c == quote || c == '\\') fprintf(fp, "\\%c", c); - else if (c < ' ' || c >= 0177) - fprintf(fp, "\\%03o", c & 0377); + 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); } @@ -374,10 +380,15 @@ c = op->ob_sval[i]; if (c == quote || c == '\\') *p++ = '\\', *p++ = c; - else if (c < ' ' || c >= 0177) { - sprintf(p, "\\%03o", c & 0377); - while (*p != '\0') - p++; + 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 *p++ = c;
