diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-02-15 16:13:15 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-02-15 16:13:15 (GMT) |
commit | c6e348a28b0d74bc880f56b2f2db6f8c97f1b6ca (patch) | |
tree | eb9367fd41589fb3a37dc89007851926dbfe6cd4 | |
parent | 13b1a0635f7e5f4c9fce04fe3474d16418d57522 (diff) | |
download | tcl-c6e348a28b0d74bc880f56b2f2db6f8c97f1b6ca.zip tcl-c6e348a28b0d74bc880f56b2f2db6f8c97f1b6ca.tar.gz tcl-c6e348a28b0d74bc880f56b2f2db6f8c97f1b6ca.tar.bz2 |
Fix [d43f96c1a8]: string trimright is broken for Emoji
-rw-r--r-- | generic/tclUtil.c | 17 | ||||
-rw-r--r-- | tests/string.test | 8 |
2 files changed, 13 insertions, 12 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index d7baedd..0e3449d 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1686,7 +1686,7 @@ TclTrimRight( * rely on (trim[numTrim] == '\0'). */ { const char *pp, *p = bytes + numBytes; - Tcl_UniChar ch1 = 0; + int ch1, ch2; /* Empty strings -> nothing to do */ if ((numBytes == 0) || (numTrim == 0)) { @@ -1700,12 +1700,14 @@ TclTrimRight( do { const char *q = trim; int pInc = 0, bytesLeft = numTrim; - Tcl_UniChar ch2 = 0; pp = TclUtfPrev(p, bytes); +#if TCL_UTF_MAX <= 4 + pp = TclUtfPrev(pp, bytes); +#endif do { pp += pInc; - pInc = TclUtfToUniChar(pp, &ch1); + pInc = TclUtfToUCS4(pp, &ch1); } while (pp + pInc < p); /* @@ -1713,7 +1715,7 @@ TclTrimRight( */ do { - int qInc = TclUtfToUniChar(q, &ch2); + int qInc = TclUtfToUCS4(q, &ch2); if (ch1 == ch2) { break; @@ -1766,7 +1768,7 @@ TclTrimLeft( * rely on (trim[numTrim] == '\0'). */ { const char *p = bytes; - Tcl_UniChar ch1 = 0; + int ch1, ch2; /* Empty strings -> nothing to do */ if ((numBytes == 0) || (numTrim == 0)) { @@ -1778,8 +1780,7 @@ TclTrimLeft( */ do { - Tcl_UniChar ch2 = 0; - int pInc = TclUtfToUniChar(p, &ch1); + int pInc = TclUtfToUCS4(p, &ch1); const char *q = trim; int bytesLeft = numTrim; @@ -1788,7 +1789,7 @@ TclTrimLeft( */ do { - int qInc = TclUtfToUniChar(q, &ch2); + int qInc = TclUtfToUCS4(q, &ch2); if (ch1 == ch2) { break; diff --git a/tests/string.test b/tests/string.test index 3f0a04b..3ac3060 100644 --- a/tests/string.test +++ b/tests/string.test @@ -1645,13 +1645,13 @@ test string-21.13 {string wordend, unicode} { test string-21.14 {string wordend, unicode} { string wordend "\uC700\uC700 abc" 8 } 6 -test string-21.17 {string trim, unicode} knownBug { +test string-21.17 {string trim, unicode} { string trim "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD83D\uDE02 } "Hello world!" test string-21.18 {string trimleft, unicode} { string trimleft "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD83D\uDE02 } "Hello world!\uD83D\uDE02" -test string-21.19 {string trimright, unicode} knownBug { +test string-21.19 {string trimright, unicode} { string trimright "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD83D\uDE02 } "\uD83D\uDE02Hello world!" test string-21.20 {string trim, unicode} { @@ -1663,13 +1663,13 @@ test string-21.21 {string trimleft, unicode} { test string-21.22 {string trimright, unicode} { string trimright "\uF602Hello world!\uF602" \uD83D\uDE02 } "\uF602Hello world!\uF602" -test string-21.23 {string trim, unicode} knownBug { +test string-21.23 {string trim, unicode} { string trim "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD93D\uDE02 } "\uD83D\uDE02Hello world!\uD83D\uDE02" test string-21.24 {string trimleft, unicode} { string trimleft "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD93D\uDE02 } "\uD83D\uDE02Hello world!\uD83D\uDE02" -test string-21.25 {string trimright, unicode} knownBug { +test string-21.25 {string trimright, unicode} { string trimright "\uD83D\uDE02Hello world!\uD83D\uDE02" \uD93D\uDE02 } "\uD83D\uDE02Hello world!\uD83D\uDE02" |