summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclExecute.c102
1 files changed, 56 insertions, 46 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index f54155d..663d650 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -4732,6 +4732,46 @@ TEBCresume(
O2S(objResultPtr)));
NEXT_INST_F(1, 2, 1);
+ case INST_STR_RANGE_IMM:
+ valuePtr = OBJ_AT_TOS;
+ fromIdx = TclGetInt4AtPtr(pc+1);
+ toIdx = TclGetInt4AtPtr(pc+5);
+ length = Tcl_GetCharLength(valuePtr);
+ TRACE(("\"%.20s\" %d %d", O2S(valuePtr), fromIdx, toIdx));
+
+ /*
+ * Adjust indices for end-based indexing.
+ */
+
+ if (fromIdx < -1) {
+ fromIdx += 1 + length;
+ if (fromIdx < 0) {
+ fromIdx = 0;
+ }
+ } else if (fromIdx >= length) {
+ fromIdx = length;
+ }
+ if (toIdx < -1) {
+ toIdx += 1 + length;
+ if (toIdx < 0) {
+ toIdx = 0;
+ }
+ } else if (toIdx >= length) {
+ toIdx = length - 1;
+ }
+
+ /*
+ * Check if we can do a sane substring.
+ */
+
+ if (fromIdx <= toIdx) {
+ objResultPtr = Tcl_GetRange(valuePtr, fromIdx, toIdx);
+ } else {
+ TclNewObj(objResultPtr);
+ }
+ TRACE_APPEND(("%.30s\n", O2S(objResultPtr)));
+ NEXT_INST_F(9, 1, 1);
+
{
Tcl_UniChar *ustring1, *ustring2, *ustring3, *end, *p;
int length3;
@@ -4741,9 +4781,12 @@ TEBCresume(
valuePtr = OBJ_AT_TOS; /* "Main" string. */
value3Ptr = OBJ_UNDER_TOS; /* "Target" string. */
value2Ptr = OBJ_AT_DEPTH(2); /* "Source" string. */
- if (value3Ptr == value2Ptr || valuePtr == value2Ptr) {
+ if (value3Ptr == value2Ptr) {
objResultPtr = valuePtr;
NEXT_INST_V(1, 3, 1);
+ } else if (valuePtr == value2Ptr) {
+ objResultPtr = value3Ptr;
+ NEXT_INST_V(1, 3, 1);
}
ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length);
if (length == 0) {
@@ -4754,6 +4797,13 @@ TEBCresume(
if (length2 > length || length2 == 0) {
objResultPtr = valuePtr;
NEXT_INST_V(1, 3, 1);
+ } else if (length2 == length) {
+ if (memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * length)) {
+ objResultPtr = valuePtr;
+ } else {
+ objResultPtr = value3Ptr;
+ }
+ NEXT_INST_V(1, 3, 1);
}
ustring3 = Tcl_GetUnicodeFromObj(value3Ptr, &length3);
@@ -4761,9 +4811,9 @@ TEBCresume(
p = ustring1;
end = ustring1 + length;
for (; ustring1 < end; ustring1++) {
- if ((*ustring1 == *ustring2) &&
- (length2==1 || Tcl_UniCharNcmp(ustring1, ustring2,
- (unsigned long) length2) == 0)) {
+ if ((*ustring1 == *ustring2) && (length2==1 ||
+ memcmp(ustring1, ustring2, sizeof(Tcl_UniChar) * length2)
+ == 0)) {
if (p != ustring1) {
Tcl_AppendUnicodeToObj(objResultPtr, p, ustring1-p);
p = ustring1 + length2;
@@ -4794,8 +4844,8 @@ TEBCresume(
if (length2 > 0 && length2 <= length) {
end = ustring1 + length - length2 + 1;
for (p=ustring1 ; p<end ; p++) {
- if ((*p == *ustring2) && TclUniCharNcmp(ustring2, p,
- (unsigned long) length2) == 0) {
+ if ((*p == *ustring2) &&
+ memcmp(ustring2,p,sizeof(Tcl_UniChar)*length2) == 0) {
match = p - ustring1;
break;
}
@@ -4807,46 +4857,6 @@ TEBCresume(
TclNewIntObj(objResultPtr, match);
NEXT_INST_F(1, 2, 1);
-
- case INST_STR_RANGE_IMM:
- valuePtr = OBJ_AT_TOS;
- fromIdx = TclGetInt4AtPtr(pc+1);
- toIdx = TclGetInt4AtPtr(pc+5);
- length = Tcl_GetCharLength(valuePtr);
- TRACE(("\"%.20s\" %d %d", O2S(valuePtr), fromIdx, toIdx));
-
- /*
- * Adjust indices for end-based indexing.
- */
-
- if (fromIdx < -1) {
- fromIdx += 1 + length;
- if (fromIdx < 0) {
- fromIdx = 0;
- }
- } else if (fromIdx >= length) {
- fromIdx = length;
- }
- if (toIdx < -1) {
- toIdx += 1 + length;
- if (toIdx < 0) {
- toIdx = 0;
- }
- } else if (toIdx >= length) {
- toIdx = length - 1;
- }
-
- /*
- * Check if we can do a sane substring.
- */
-
- if (fromIdx <= toIdx) {
- objResultPtr = Tcl_GetRange(valuePtr, fromIdx, toIdx);
- } else {
- TclNewObj(objResultPtr);
- }
- TRACE_APPEND(("%.30s\n", O2S(objResultPtr)));
- NEXT_INST_F(9, 1, 1);
}
case INST_STR_MATCH: