From d97e25b2ad96e4be2e23c349c2d0e6d44cab07e4 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 16 Feb 2021 08:10:34 +0000 Subject: Fix Tcl_UtfPrev for TCL_UTF_MAX>3, so it can jump back over Emoji. Backported from 8.7, no change for TCL_UTF_MAX=3. This way, the previous fix can be slightly more simplified, and working for TCL_UTF_MAX>3 too. --- generic/tclUtf.c | 2 +- generic/tclUtil.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 5ae977a..f99c497 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -888,7 +888,7 @@ Tcl_UtfPrev( /* Continue the search backwards... */ look--; - } while (trailBytesSeen < 3); + } while (trailBytesSeen < (TCL_UTF_MAX < 4 ? 3 : 4)); /* * We've seen 3 trail bytes, so we know there will not be a diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 0e3449d..450f3bf 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1702,7 +1702,7 @@ TclTrimRight( int pInc = 0, bytesLeft = numTrim; pp = TclUtfPrev(p, bytes); -#if TCL_UTF_MAX <= 4 +#if TCL_UTF_MAX < 4 pp = TclUtfPrev(pp, bytes); #endif do { @@ -1715,14 +1715,14 @@ TclTrimRight( */ do { - int qInc = TclUtfToUCS4(q, &ch2); + pInc = TclUtfToUCS4(q, &ch2); if (ch1 == ch2) { break; } - q += qInc; - bytesLeft -= qInc; + q += pInc; + bytesLeft -= pInc; } while (bytesLeft); if (bytesLeft == 0) { -- cgit v0.12