diff options
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r-- | generic/tclCmdMZ.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 52cdf10..90b9687 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdMZ.c,v 1.4 1999/05/04 01:33:10 stanton Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.5 1999/05/04 02:57:55 stanton Exp $ */ #include "tclInt.h" @@ -806,7 +806,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) char *string1, *string2; int length1, length2; static char *options[] = { - "bytes", "compare", "equal", "first", + "bytelength", "compare", "equal", "first", "icompare", "iequal", "index", "last", "length", "map", "match", "range", "repeat", "replace", @@ -815,7 +815,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) "wordend", "wordstart", (char *) NULL }; enum options { - STR_BYTES, STR_COMPARE, STR_EQUAL, STR_FIRST, + STR_BYTELENGTH, STR_COMPARE, STR_EQUAL, STR_FIRST, STR_ICOMPARE, STR_IEQUAL, STR_INDEX, STR_LAST, STR_LENGTH, STR_MAP, STR_MATCH, STR_RANGE, STR_REPEAT, STR_REPLACE, @@ -1044,18 +1044,31 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) Tcl_SetIntObj(resultPtr, match); break; } - case STR_BYTES: + case STR_BYTELENGTH: case STR_LENGTH: { if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "string"); return TCL_ERROR; } - string1 = Tcl_GetStringFromObj(objv[2], &length1); - if ((enum options) index == STR_BYTES) { + if ((enum options) index == STR_BYTELENGTH) { + string1 = Tcl_GetStringFromObj(objv[2], &length1); Tcl_SetIntObj(resultPtr, length1); } else { - Tcl_SetIntObj(resultPtr, Tcl_NumUtfChars(string1, length1)); + /* + * If we have a ByteArray object, avoid recomputing the + * string since the byte array contains one byte per + * character. + */ + + if (objv[2]->typePtr == &tclByteArrayType) { + string1 = Tcl_GetByteArrayFromObj(objv[2], &length1); + Tcl_SetIntObj(resultPtr, length1); + } else { + string1 = Tcl_GetStringFromObj(objv[2], &length1); + Tcl_SetIntObj(resultPtr, Tcl_NumUtfChars(string1, + length1)); + } } break; } |