summaryrefslogtreecommitdiffstats
path: root/generic/tkUtil.c
diff options
context:
space:
mode:
authornijtmans@users.sourceforge.net <jan.nijtmans>2016-09-19 10:14:52 (GMT)
committernijtmans@users.sourceforge.net <jan.nijtmans>2016-09-19 10:14:52 (GMT)
commit06e86eac45f9edaa47e0a8de86a428355efc652d (patch)
tree011764b9a1c9b1b47f5d61b56f1627526961f832 /generic/tkUtil.c
parent289a1f9409c3a5c99e36925f03faa4fd06f22400 (diff)
downloadtk-tip_389.zip
tk-tip_389.tar.gz
tk-tip_389.tar.bz2
More simplificationstip_389
Diffstat (limited to 'generic/tkUtil.c')
-rw-r--r--generic/tkUtil.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index a266cb3..19b343e 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -1197,7 +1197,7 @@ TkSendVirtualEvent(
/*
*---------------------------------------------------------------------------
*
- * TkUtfToUniChar2 --
+ * TkUtfToUniChar --
*
* Almost the same as Tcl_UtfToUniChar but using int instead of Tcl_UniChar.
* This function is capable of collapsing a upper/lower pair to a single
@@ -1214,7 +1214,7 @@ TkSendVirtualEvent(
*/
int
-TkUtfToUniChar2(
+TkUtfToUniChar(
const char *src, /* The UTF-8 string. */
int *chPtr) /* Filled with the Tcl_UniChar represented by
* the UTF-8 string. */
@@ -1238,6 +1238,39 @@ TkUtfToUniChar2(
}
return len;
}
+
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TkUniCharToUtf --
+ *
+ * Almost the same as Tcl_UniCharToUtf but producing surrogates if
+ * TCL_UTF_MAX==3.
+ *
+ * Results:
+ * *buf is filled with the UTF-8 string, and the return value is the
+ * number of bytes produced.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+int TkUniCharToUtf(int ch, char *buf)
+{
+ int size = Tcl_UniCharToUtf(ch, buf);
+ if ((ch > 0xffff) && (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);
+ }
+ return size;
+}
+
+
#endif
/*
* Local Variables: