From 56440b93f33cc8198219ce97fc82266f60796eaf Mon Sep 17 00:00:00 2001 From: James Clark Date: Thu, 22 Jan 1998 08:35:51 +0000 Subject: [PATCH] Fix UTF-16 to UTF-8 conversion on surrogates. --- expat/xmltok/xmltok.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/expat/xmltok/xmltok.c b/expat/xmltok/xmltok.c index c1f81aa9..b2629ea9 100755 --- a/expat/xmltok/xmltok.c +++ b/expat/xmltok/xmltok.c @@ -250,6 +250,7 @@ void PREFIX(toUtf8)(const ENCODING *enc, \ { \ const char *from; \ for (from = *fromP; from != fromLim; from += 2) { \ + int plane; \ unsigned char lo2; \ unsigned char lo = GET_LO(from); \ unsigned char hi = GET_HI(from); \ @@ -277,10 +278,9 @@ void PREFIX(toUtf8)(const ENCODING *enc, \ case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ if (toLim - *toP < 4) \ return; \ - /* IIIIIIWW XXXXXXYY IIIIIIYY YYZZZZZ => */ \ - /* JJJJJJWW JJXXXXXX JJYYYYYY JJZZZZZ */ \ - *(*toP)++ = ((hi & 0x3) | cval4); \ - *(*toP)++ = ((lo >> 2) | 0x80); \ + plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ + *(*toP)++ = ((plane >> 2) | cval4); \ + *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ from += 2; \ lo2 = GET_LO(from); \ *(*toP)++ = (((lo & 0x3) << 4) \