Author: AlbrechtS
Date: 2011-01-07 09:23:02 -0800 (Fri, 07 Jan 2011)
New Revision: 8214
Log:
Fix to take care of Cygwin that uses UTF-16 as well as native Windows,
i.e. sizeof(wchar_t) = 2, and Unicode is UTF-16 with surrogate pairs.
Modified:
branches/branch-1.3/src/fl_utf.c
Modified: branches/branch-1.3/src/fl_utf.c
===================================================================
--- branches/branch-1.3/src/fl_utf.c 2011-01-07 16:19:30 UTC (rev 8213)
+++ branches/branch-1.3/src/fl_utf.c 2011-01-07 17:23:02 UTC (rev 8214)
@@ -410,19 +410,25 @@
Converts a UTF-8 string into a wide character string.
This function generates 32-bit wchar_t (e.g. "ucs4" as it were) except
- on win32 where it returns Utf16 with surrogate pairs where required.
+ on Windows where it returns UTF-16 with surrogate pairs where required.
+
+ Note that Windows includes Cygwin, i.e. compiled with Cygwin's POSIX
+ layer (cygwin1.dll, --enable-cygwin), either native (GDI) or X11.
*/
unsigned fl_utf8towc(const char* src, unsigned srclen,
wchar_t* dst, unsigned dstlen)
{
-#ifdef WIN32
- return fl_utf8toUtf16(src, srclen, (unsigned short*)dst, dstlen);
+#if defined(WIN32) || defined(__CYGWIN__)
+ return fl_utf8toUtf16(src, srclen, (unsigned short*)dst, dstlen);
#else
const char* p = src;
const char* e = src+srclen;
unsigned count = 0;
if (dstlen) for (;;) {
- if (p >= e) {dst[count] = 0; return count;}
+ if (p >= e) {
+ dst[count] = 0;
+ return count;
+ }
if (!(*p & 0x80)) { /* ascii */
dst[count] = *p++;
} else {
@@ -511,7 +517,7 @@
needed.
\p srclen is the number of words in \p src to convert. On Windows
- this is not necessairly the number of characters, due to there
+ this is not necessarily the number of characters, due to there
possibly being "surrogate pairs" in the UTF-16 encoding used.
On Unix wchar_t is 32 bits and each location is a character.
@@ -541,7 +547,7 @@
if (count+2 >= dstlen) {dst[count] = 0; count += 2; break;}
dst[count++] = 0xc0 | (ucs >> 6);
dst[count++] = 0x80 | (ucs & 0x3F);
-#ifdef WIN32
+#if defined(WIN32) || defined(__CYGWIN__)
} else if (ucs >= 0xd800 && ucs <= 0xdbff && i < srclen &&
src[i] >= 0xdc00 && src[i] <= 0xdfff) {
/* surrogate pair */
@@ -561,7 +567,7 @@
dst[count++] = 0x80 | ((ucs >> 6) & 0x3F);
dst[count++] = 0x80 | (ucs & 0x3F);
} else {
-#ifndef WIN32
+#if !(defined(WIN32) || defined(__CYGWIN__))
J1:
#endif
/* all others are 3 bytes: */
@@ -578,7 +584,7 @@
count++;
} else if (ucs < 0x800U) { /* 2 bytes */
count += 2;
-#ifdef WIN32
+#if defined(WIN32) || defined(__CYGWIN__)
} else if (ucs >= 0xd800 && ucs <= 0xdbff && i < srclen-1 &&
src[i+1] >= 0xdc00 && src[i+1] <= 0xdfff) {
/* surrogate pair */
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit