Changeset: 29167418829a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/29167418829a
Modified Files:
        clients/odbc/driver/ODBCUtil.c
        common/stream/stdio_stream.c
        common/utils/mutils.c
Branch: ascii-flag
Log Message:

Clever way of calculating UTF-16 high and low surrogates.


diffs (49 lines):

diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c
--- a/clients/odbc/driver/ODBCUtil.c
+++ b/clients/odbc/driver/ODBCUtil.c
@@ -255,12 +255,12 @@ ODBCutf82wchar(const SQLCHAR *src,
                        if (c > 0x10FFFF || (c & 0x1FF800) == 0x00D800)
                                return "Illegal code point";
 #if SIZEOF_SQLWCHAR == 2
-                               if (i + 2 >= buflen)
-                                       break;
-                               buf[i++] = 0xD800 | ((c - 0x10000) >> 10);
-                               buf[i++] = 0xDC00 | (c & 0x3FF);
+                       if (i + 2 >= buflen)
+                               break;
+                       buf[i++] = 0xD7C0 + (c >> 10);
+                       buf[i++] = 0xDC00 + (c & 0x03FF);
 #else
-                               buf[i++] = c;
+                       buf[i++] = c;
 #endif
                        j += 4;
                } else {
diff --git a/common/stream/stdio_stream.c b/common/stream/stdio_stream.c
--- a/common/stream/stdio_stream.c
+++ b/common/stream/stdio_stream.c
@@ -241,8 +241,8 @@ utf8towchar(const char *src)
                                | (src[j+2] & 0x3F) << 6
                                | (src[j+3] & 0x3F);
 #if SIZEOF_WCHAR_T == 2
-                       dest[i++] = 0xD800 | ((c - 0x10000) >> 10);
-                       dest[i++] = 0xDE00 | (c & 0x3FF);
+                       dest[i++] = 0xD7C0 + (c >> 10);
+                       dest[i++] = 0xDC00 + (c & 0x03FF);
 #else
                        dest[i++] = c;
 #endif
diff --git a/common/utils/mutils.c b/common/utils/mutils.c
--- a/common/utils/mutils.c
+++ b/common/utils/mutils.c
@@ -125,8 +125,8 @@ utf8towchar(const char *src)
                                | (src[j+2] & 0x3F) << 6
                                | (src[j+3] & 0x3F);
 #if SIZEOF_WCHAR_T == 2
-                       dest[i++] = 0xD800 | ((c - 0x10000) >> 10);
-                       dest[i++] = 0xDE00 | (c & 0x3FF);
+                       dest[i++] = 0xD7C0 + (c >> 10);
+                       dest[i++] = 0xDC00 + (c & 0x03FF);
 #else
                        dest[i++] = c;
 #endif
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to