From 017257e0ef3f20643166931986ea36eeee97f049 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 23 May 2020 22:07:53 +0000 Subject: Rewrite "string wordend" to use the Tcl_UniChar array. --- generic/tclCmdMZ.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 0e624c6..88bf2ec 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -2709,28 +2709,26 @@ StringEndCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { int ch; - const char *p, *end, *string; - int cur, index, length, numChars; + const Tcl_UniChar *p, *end, *string; + int cur, index, length; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "string index"); return TCL_ERROR; } - string = TclGetStringFromObj(objv[1], &length); - numChars = Tcl_NumUtfChars(string, length); - if (TclGetIntForIndexM(interp, objv[2], numChars-1, &index) != TCL_OK) { + string = Tcl_GetUnicodeFromObj(objv[1], &length); + if (TclGetIntForIndexM(interp, objv[2], length-1, &index) != TCL_OK) { return TCL_ERROR; } - string = TclGetStringFromObj(objv[1], &length); if (index < 0) { index = 0; } - if (index < numChars) { - p = Tcl_UtfAtIndex(string, index); + if (index < length) { + p = &string[index]; end = string+length; for (cur = index; p < end; cur++) { - p += TclUtfToUCS4(p, &ch); + p += TclUniCharToUCS4(p, &ch); if (!Tcl_UniCharIsWordChar(ch)) { break; } @@ -2739,7 +2737,7 @@ StringEndCmd( cur++; } } else { - cur = numChars; + cur = length; } Tcl_SetObjResult(interp, Tcl_NewWideIntObj(cur)); return TCL_OK; -- cgit v0.12