diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-04-26 15:11:41 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-04-26 15:11:41 (GMT) |
commit | d28ffce7cd1cfb32c243f8384664d3a332ecbcb4 (patch) | |
tree | 4adbc1973c217db39dfddf2c25856f7748e97fd5 /generic/tclUtf.c | |
parent | c2cd944d57728b603d560213a7ab5d455c7e3f98 (diff) | |
download | tcl-d28ffce7cd1cfb32c243f8384664d3a332ecbcb4.zip tcl-d28ffce7cd1cfb32c243f8384664d3a332ecbcb4.tar.gz tcl-d28ffce7cd1cfb32c243f8384664d3a332ecbcb4.tar.bz2 |
Cherry-pick Tcl_UniCharAtIndex() implementation from [6596c4af31], but adapted to the needs of TIPs 389/542.
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 45a7f1e..1138372 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1081,7 +1081,7 @@ Tcl_UtfPrev( * * Tcl_UniCharAtIndex -- * - * Returns the Tcl_UniChar represented at the specified character + * Returns the Unicode character represented at the specified character * (not byte) position in the UTF-8 string. * * Results: @@ -1098,28 +1098,10 @@ Tcl_UniCharAtIndex( const char *src, /* The UTF-8 string to dereference. */ int index) /* The position of the desired character. */ { - Tcl_UniChar ch = 0; - int fullchar = 0; -#if TCL_UTF_MAX <= 3 - int len = 0; -#endif + int ch = 0; - while (index-- >= 0) { -#if TCL_UTF_MAX <= 3 - src += (len = TclUtfToUniChar(src, &ch)); -#else - src += TclUtfToUniChar(src, &ch); -#endif - } - fullchar = ch; -#if TCL_UTF_MAX <= 3 - if ((ch >= 0xD800) && (len < 3)) { - /* If last Tcl_UniChar was a high surrogate, combine with low surrogate */ - (void)TclUtfToUniChar(src, &ch); - fullchar = (((fullchar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; - } -#endif - return fullchar; + TclUtfToUCS4(Tcl_UtfAtIndex(src, index), &ch); + return ch; } /* |