diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-10-15 09:20:17 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-10-15 09:20:17 (GMT) |
commit | 178635dd58322a9e3dd219f55b81023fac724c4f (patch) | |
tree | 4931999e3dd2fbea60fd195fd95654302c5183ab /generic/tkUtil.c | |
parent | e3b515e0b616ab42cff45b183f8b41cd2b8ba7cc (diff) | |
parent | be42ed39b45938000bdf6dc5b4f2c7cab5624927 (diff) | |
download | tk-178635dd58322a9e3dd219f55b81023fac724c4f.zip tk-178635dd58322a9e3dd219f55b81023fac724c4f.tar.gz tk-178635dd58322a9e3dd219f55b81023fac724c4f.tar.bz2 |
Merge 8.6
Diffstat (limited to 'generic/tkUtil.c')
-rw-r--r-- | generic/tkUtil.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 4844bc2..e014a41 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -1243,8 +1243,8 @@ TkUtfToUniChar( * * TkUniCharToUtf -- * - * Almost the same as Tcl_UniCharToUtf but producing surrogates if - * TCL_UTF_MAX==3. So, up to 6 bytes might be produced. + * Almost the same as Tcl_UniCharToUtf but producing 4-byte UTF-8 + * sequences even when TCL_UTF_MAX==3. So, up to 4 bytes might be produced. * * Results: * *buf is filled with the UTF-8 string, and the return value is the @@ -1261,10 +1261,12 @@ size_t TkUniCharToUtf(int ch, char *buf) size_t size = Tcl_UniCharToUtf(ch, buf); if ((((unsigned)(ch - 0x10000) <= 0xFFFFF)) && (size < 4)) { /* Hey, this is wrong, we must be running TCL_UTF_MAX==3 - * The best thing we can do is spit out 2 surrogates */ - ch -= 0x10000; - size = Tcl_UniCharToUtf(((ch >> 10) | 0xd800), buf); - size += Tcl_UniCharToUtf(((ch & 0x3ff) | 0xdc00), buf+size); + * The best thing we can do is spit out a 4-byte UTF-8 character */ + buf[3] = (char) ((ch | 0x80) & 0xBF); + buf[2] = (char) (((ch >> 6) | 0x80) & 0xBF); + buf[1] = (char) (((ch >> 12) | 0x80) & 0xBF); + buf[0] = (char) ((ch >> 18) | 0xF0); + size = 4; } return size; } |