summaryrefslogtreecommitdiffstats
path: root/generic/tclCompCmdsSZ.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-07 21:21:00 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-07 21:21:00 (GMT)
commitb4d6691add28bb5928fd51cf76bf7f6d9c78f5cc (patch)
tree9826b49b65c0a7f4c416ad3b49082be9096d07fb /generic/tclCompCmdsSZ.c
parent3492c92f3dcb820bd5f7aa833e340b6e1eb8f1c5 (diff)
parentf337281f750a928dcc07884286cc1f4cceeab809 (diff)
downloadtcl-b4d6691add28bb5928fd51cf76bf7f6d9c78f5cc.zip
tcl-b4d6691add28bb5928fd51cf76bf7f6d9c78f5cc.tar.gz
tcl-b4d6691add28bb5928fd51cf76bf7f6d9c78f5cc.tar.bz2
Merge 8.6
Diffstat (limited to 'generic/tclCompCmdsSZ.c')
-rw-r--r--generic/tclCompCmdsSZ.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index 294ee25..05ef8e0 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -1005,6 +1005,14 @@ TclCompileStringReplaceCmd(
* We handle these replacements specially: first character (where
* idx1=idx2=0) and last character (where idx1=idx2=TCL_INDEX_END). Anything
* else and the semantics get rather screwy.
+ *
+ * TODO: These seem to be very narrow cases. They are not even
+ * covered by the test suite, and any programming that ends up
+ * here could have been coded by the programmer using [string range]
+ * and [string cat]. [*] Not clear at all to me that the bytecode
+ * generated here is worthwhile.
+ *
+ * [*] Except for the empty string exceptions. UGGGGHHHH.
*/
if (idx1 == 0 && idx2 == 0) {
@@ -1022,6 +1030,14 @@ TclCompileStringReplaceCmd(
}
/* Replace first */
CompileWord(envPtr, replacementTokenPtr, interp, 4);
+
+ /*
+ * NOTE: The following tower of bullshit is present because
+ * [string replace] was boneheadedly defined not to replace
+ * empty strings, so we actually have to detect the empty
+ * string case and treat it differently.
+ */
+
OP4( OVER, 1);
PUSH( "");
OP( STR_EQ);
@@ -1051,6 +1067,9 @@ TclCompileStringReplaceCmd(
}
/* Replace last */
CompileWord(envPtr, replacementTokenPtr, interp, 4);
+
+ /* More bullshit; see NOTE above. */
+
OP4( OVER, 1);
PUSH( "");
OP( STR_EQ);