diff options
author | andy <andrew.m.goth@gmail.com> | 2017-09-23 16:36:49 (GMT) |
---|---|---|
committer | andy <andrew.m.goth@gmail.com> | 2017-09-23 16:36:49 (GMT) |
commit | 389672a1c0eeb599e859471eeddcc9d0e6e76f96 (patch) | |
tree | 57819ce04ff85e3dd4a792ed3613570b137cdbf0 | |
parent | 9c874d0c1530c3e72946825dfff368e352c4dcc5 (diff) | |
download | tcl-amg_string_insert.zip tcl-amg_string_insert.tar.gz tcl-amg_string_insert.tar.bz2 |
Simplify implementation of non-bytecoded [string replace]amg_string_insert
-rw-r--r-- | generic/tclCmdMZ.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 5410604..3243afb 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -2357,7 +2357,6 @@ StringRplcCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { int first, last, length; /* Replacement indexes and string length */ - int del; /* Number of characters to delete */ Tcl_Obj *strObj; /* String being modified */ Tcl_Obj *insObj; /* Substring to insert, may be NULL */ Tcl_Obj *outObj; /* Output object */ @@ -2374,25 +2373,23 @@ StringRplcCmd( return TCL_ERROR; } - if (objc == 5) { - insObj = objv[4]; - } else { - insObj = NULL; - } - if (first < 0) { first = 0; } if (last >= first) { - del = last - first + 1; - } else { - del = 0; - insObj = NULL; - } + if (objc == 5) { + insObj = objv[4]; + } else { + insObj = NULL; + } - if (!(outObj = Tcl_ReplaceObj(interp, strObj, first, del, insObj))) { - return TCL_ERROR; + if (!(outObj = Tcl_ReplaceObj(interp, strObj, first, + last - first + 1, insObj))) { + return TCL_ERROR; + } + } else { + outObj = strObj; } Tcl_SetObjResult(interp, outObj); |