summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2014-02-04 09:02:23 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2014-02-04 09:02:23 (GMT)
commita72ae0f931f9ac8a78ef7b78f854ae68e66f9dd1 (patch)
tree9c768c5a542df4343084438ea39ffe92de951832 /generic
parentdc81fd618b33c6e9c6b8fa4b9595229ce3809f01 (diff)
downloadtcl-a72ae0f931f9ac8a78ef7b78f854ae68e66f9dd1.zip
tcl-a72ae0f931f9ac8a78ef7b78f854ae68e66f9dd1.tar.gz
tcl-a72ae0f931f9ac8a78ef7b78f854ae68e66f9dd1.tar.bz2
make the printing of source much less inclined to be fazed by non-ASCII chars
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCompile.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c
index c5d0107..347e3f0 100644
--- a/generic/tclCompile.c
+++ b/generic/tclCompile.c
@@ -5318,7 +5318,7 @@ PrintSourceToObj(
int maxChars) /* Maximum number of chars to print. */
{
register const char *p;
- register int i = 0;
+ register int i = 0, len;
if (stringPtr == NULL) {
Tcl_AppendToObj(appendObj, "\"\"", -1);
@@ -5327,32 +5327,50 @@ PrintSourceToObj(
Tcl_AppendToObj(appendObj, "\"", -1);
p = stringPtr;
- for (; (*p != '\0') && (i < maxChars); p++, i++) {
- switch (*p) {
+ for (; (*p != '\0') && (i < maxChars); p+=len) {
+ Tcl_UniChar ch;
+
+ len = TclUtfToUniChar(p, &ch);
+ switch (ch) {
case '"':
Tcl_AppendToObj(appendObj, "\\\"", -1);
+ i += 2;
continue;
case '\f':
Tcl_AppendToObj(appendObj, "\\f", -1);
+ i += 2;
continue;
case '\n':
Tcl_AppendToObj(appendObj, "\\n", -1);
+ i += 2;
continue;
case '\r':
Tcl_AppendToObj(appendObj, "\\r", -1);
+ i += 2;
continue;
case '\t':
Tcl_AppendToObj(appendObj, "\\t", -1);
+ i += 2;
continue;
case '\v':
Tcl_AppendToObj(appendObj, "\\v", -1);
+ i += 2;
continue;
default:
- Tcl_AppendPrintfToObj(appendObj, "%c", *p);
+ if (ch < 0x20 || ch >= 0x7f) {
+ Tcl_AppendPrintfToObj(appendObj, "\\u%04x", ch);
+ i += 6;
+ } else {
+ Tcl_AppendPrintfToObj(appendObj, "%c", ch);
+ i++;
+ }
continue;
}
}
Tcl_AppendToObj(appendObj, "\"", -1);
+ if (*p != '\0') {
+ Tcl_AppendToObj(appendObj, "...", -1);
+ }
}
#ifdef TCL_COMPILE_STATS