diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-12 19:47:06 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-12 19:47:06 (GMT) |
commit | e47d4943353da4de3f0faf8dd95139d2ed4f7260 (patch) | |
tree | 6f02a9dd5e15e0b5e0951c2d3e369f991812410f /generic/tclUtf.c | |
parent | d2d5ffc3b68149d508018fa46c9a210e4115b4b1 (diff) | |
parent | dd3240d86038ac4267439eb5535a17293f125b12 (diff) | |
download | tcl-e47d4943353da4de3f0faf8dd95139d2ed4f7260.zip tcl-e47d4943353da4de3f0faf8dd95139d2ed4f7260.tar.gz tcl-e47d4943353da4de3f0faf8dd95139d2ed4f7260.tar.bz2 |
Merge 8.7
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 19 |
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; } /* |