summaryrefslogtreecommitdiffstats
path: root/generic/tclUtf.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-12 19:47:06 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-12 19:47:06 (GMT)
commite47d4943353da4de3f0faf8dd95139d2ed4f7260 (patch)
tree6f02a9dd5e15e0b5e0951c2d3e369f991812410f /generic/tclUtf.c
parentd2d5ffc3b68149d508018fa46c9a210e4115b4b1 (diff)
parentdd3240d86038ac4267439eb5535a17293f125b12 (diff)
downloadtcl-e47d4943353da4de3f0faf8dd95139d2ed4f7260.zip
tcl-e47d4943353da4de3f0faf8dd95139d2ed4f7260.tar.gz
tcl-e47d4943353da4de3f0faf8dd95139d2ed4f7260.tar.bz2
Merge 8.7
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r--generic/tclUtf.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index df27b16..74e7888 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -1143,10 +1143,23 @@ Tcl_UniCharAtIndex(
const char *src, /* The UTF-8 string to dereference. */
size_t index) /* The position of the desired character. */
{
- int ch = 0;
+ Tcl_UniChar ch = 0;
+ int i = 0;
- TclUtfToUCS4(Tcl_UtfAtIndex(src, index), &ch);
- return ch;
+ if (index != TCL_INDEX_NONE) {
+ while (index--) {
+ i = TclUtfToUniChar(src, &ch);
+ src += i;
+ }
+#if TCL_UTF_MAX <= 3
+ if ((ch >= 0xD800) && (i < 3)) {
+ /* Index points at character following high Surrogate */
+ return -1;
+ }
+#endif
+ }
+ TclUtfToUCS4(src, &i);
+ return i;
}
/*