summaryrefslogtreecommitdiffstats
path: root/generic/tclExecute.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2013-10-03 13:32:06 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2013-10-03 13:32:06 (GMT)
commitf9427cdbfd828dbabe79facdc3d757146c090563 (patch)
tree0fc8c55a7c7074e884924430835fce4b9eaeabcc /generic/tclExecute.c
parentc9e288f12b7d1802ea33bb58cc546f1a1ce153e1 (diff)
downloadtcl-f9427cdbfd828dbabe79facdc3d757146c090563.zip
tcl-f9427cdbfd828dbabe79facdc3d757146c090563.tar.gz
tcl-f9427cdbfd828dbabe79facdc3d757146c090563.tar.bz2
cleaner and faster 'string trim'
Diffstat (limited to 'generic/tclExecute.c')
-rw-r--r--generic/tclExecute.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 83f68fd..8470389 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -5258,19 +5258,41 @@ TEBCresume(
{
const char *string1, *string2;
+ int trim1, trim2;
+ case INST_STRTRIM:
+ valuePtr = OBJ_UNDER_TOS; /* String */
+ value2Ptr = OBJ_AT_TOS; /* TrimSet */
+ string2 = TclGetStringFromObj(value2Ptr, &length2);
+ string1 = TclGetStringFromObj(valuePtr, &length);
+ trim1 = TclTrimLeft(string1, length, string2, length2);
+ if (trim1 < length) {
+ trim2 = TclTrimRight(string1, length, string2, length2);
+ } else {
+ trim2 = 0;
+ }
+ if (trim1 == 0 && trim2 == 0) {
+ TRACE_WITH_OBJ(("\"%.30s\" \"%.30s\" => ", valuePtr, value2Ptr),
+ valuePtr);
+ NEXT_INST_F(1, 1, 0);
+ } else {
+ objResultPtr = Tcl_NewStringObj(string1+trim1, length-trim1-trim2);
+ TRACE_WITH_OBJ(("\"%.30s\" \"%.30s\" => ", valuePtr, value2Ptr),
+ objResultPtr);
+ NEXT_INST_F(1, 2, 1);
+ }
case INST_STRTRIM_LEFT:
valuePtr = OBJ_UNDER_TOS; /* String */
value2Ptr = OBJ_AT_TOS; /* TrimSet */
string2 = TclGetStringFromObj(value2Ptr, &length2);
string1 = TclGetStringFromObj(valuePtr, &length);
- match = TclTrimLeft(string1, length, string2, length2);
- if (match == 0) {
+ trim1 = TclTrimLeft(string1, length, string2, length2);
+ if (trim1 == 0) {
TRACE_WITH_OBJ(("\"%.30s\" \"%.30s\" => ", valuePtr, value2Ptr),
valuePtr);
NEXT_INST_F(1, 1, 0);
} else {
- objResultPtr = Tcl_NewStringObj(string1+match, length-match);
+ objResultPtr = Tcl_NewStringObj(string1+trim1, length-trim1);
TRACE_WITH_OBJ(("\"%.30s\" \"%.30s\" => ", valuePtr, value2Ptr),
objResultPtr);
NEXT_INST_F(1, 2, 1);
@@ -5280,11 +5302,11 @@ TEBCresume(
value2Ptr = OBJ_AT_TOS; /* TrimSet */
string2 = TclGetStringFromObj(value2Ptr, &length2);
string1 = TclGetStringFromObj(valuePtr, &length);
- match = TclTrimRight(string1, length, string2, length2);
- if (match == 0) {
+ trim2 = TclTrimRight(string1, length, string2, length2);
+ if (trim2 == 0) {
NEXT_INST_F(1, 1, 0);
} else {
- objResultPtr = Tcl_NewStringObj(string1, length-match);
+ objResultPtr = Tcl_NewStringObj(string1, length-trim2);
NEXT_INST_F(1, 2, 1);
}
}