summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclCmdMZ.c14
-rw-r--r--tests/string.test2
2 files changed, 13 insertions, 3 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index d4fa4e9..6515d98 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -2396,12 +2396,22 @@ StringStartCmd(
cur = 0;
if (index > 0) {
p = Tcl_UtfAtIndex(string, index);
+
+ TclUtfToUniChar(p, &ch);
for (cur = index; cur >= 0; cur--) {
- TclUtfToUniChar(p, &ch);
+ int delta = 0;
+ const char *next;
+
if (!Tcl_UniCharIsWordChar(ch)) {
break;
}
- p = Tcl_UtfPrev(p, string);
+
+ next = Tcl_UtfPrev(p, string);
+ do {
+ next += delta;
+ delta = TclUtfToUniChar(next, &ch);
+ } while (next + delta < p);
+ p = next;
}
if (cur != index) {
cur += 1;
diff --git a/tests/string.test b/tests/string.test
index 05a0623..54b9c95 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -1570,7 +1570,7 @@ test string-22.12 {string wordstart, unicode} {
test string-22.13 {string wordstart, unicode} {
string wordstart "\uc700\uc700 abc" 8
} 3
-test string-22.14 {string wordstart, invalid UTF-8} knownBug {
+test string-22.14 {string wordstart, invalid UTF-8} {
# See Bug c61818e4c9
set demo [bytestring "abc def\xE0\xA9ghi"]
string index $demo [string wordstart $demo 10]