summaryrefslogtreecommitdiffstats
path: root/generic/tkUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-26 20:48:07 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-26 20:48:07 (GMT)
commitfdf27f95df08c89a26532ee79d5d771f10b05837 (patch)
tree878c658370eaa732a0b9aae67ee85b6c8afb6e21 /generic/tkUtil.c
parentfcbf569858ecb8e78138c709e4a39babca23e584 (diff)
parenteca06f257b5b2c6a01a466e4e4501eb3f6f549a6 (diff)
downloadtk-fdf27f95df08c89a26532ee79d5d771f10b05837.zip
tk-fdf27f95df08c89a26532ee79d5d771f10b05837.tar.gz
tk-fdf27f95df08c89a26532ee79d5d771f10b05837.tar.bz2
Merge 8.6
Diffstat (limited to 'generic/tkUtil.c')
-rw-r--r--generic/tkUtil.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index e014a41..098c286 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -1215,26 +1215,23 @@ TkSendVirtualEvent(
size_t
TkUtfToUniChar(
const char *src, /* The UTF-8 string. */
- int *chPtr) /* Filled with the Tcl_UniChar represented by
+ int *chPtr) /* Filled with the Unicode value represented by
* the UTF-8 string. */
{
Tcl_UniChar uniChar = 0;
size_t len = Tcl_UtfToUniChar(src, &uniChar);
- if ((uniChar & 0xfc00) == 0xd800) {
- Tcl_UniChar high = uniChar;
+ if ((uniChar & 0xFC00) == 0xD800) {
+ Tcl_UniChar low = uniChar;
/* This can only happen if Tcl is compiled with TCL_UTF_MAX=4,
* or when a high surrogate character is detected in UTF-8 form */
- size_t len2 = Tcl_UtfToUniChar(src+len, &uniChar);
- if ((uniChar & 0xfc00) == 0xdc00) {
- *chPtr = (((high & 0x3ff) << 10) | (uniChar & 0x3ff)) + 0x10000;
- len += len2;
- } else {
- *chPtr = high;
+ size_t len2 = Tcl_UtfToUniChar(src+len, &low);
+ if ((uniChar & 0xFC00) == 0xDC00) {
+ *chPtr = (((uniChar & 0x3FF) << 10) | (low & 0x3FF)) + 0x10000;
+ return len + len2;
}
- } else {
- *chPtr = uniChar;
}
+ *chPtr = uniChar;
return len;
}
@@ -1258,17 +1255,16 @@ TkUtfToUniChar(
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 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;
+ if (((unsigned)(ch - 0x10000) <= 0xFFFFF)) {
+ /* Spit out a 4-byte UTF-8 character */
+ *buf++ = (char) ((ch >> 18) | 0xF0);
+ *buf++ = (char) (((ch >> 12) | 0x80) & 0xBF);
+ *buf++ = (char) (((ch >> 6) | 0x80) & 0xBF);
+ *buf = (char) ((ch | 0x80) & 0xBF);
+ return 4;
+ } else {
+ return Tcl_UniCharToUtf(ch, buf);
}
- return size;
}