Qian Hong : riched20: Added support for UTF8 BOM stream.

Alexandre Julliard julliard at winehq.org
Fri Aug 17 10:37:46 CDT 2012


Module: wine
Branch: master
Commit: cb8c500ee67a64c4e5f08434d5ae0634bf82e375
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cb8c500ee67a64c4e5f08434d5ae0634bf82e375

Author: Qian Hong <fracting at gmail.com>
Date:   Fri Aug 17 03:05:56 2012 +0800

riched20: Added support for UTF8 BOM stream.

---

 dlls/riched20/editor.c       |   22 +++++++++++++++++++---
 dlls/riched20/tests/editor.c |    4 ++--
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 6e0fb3c..18cd159 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -283,9 +283,10 @@ static ME_TextBuffer *ME_MakeText(void) {
 
 static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
 {
-  WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
   WCHAR *pText;
   LRESULT total_bytes_read = 0;
+  BOOL is_read = FALSE;
+  static const char bom_utf8[] = {0xEF, 0xBB, 0xBF};
 
   TRACE("%08x %p\n", dwFormat, stream);
 
@@ -304,8 +305,23 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
 
     if (!(dwFormat & SF_UNICODE))
     {
-      /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
-      nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE);
+      WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
+      char * buf = stream->buffer;
+      DWORD size = stream->dwSize;
+      DWORD cp = CP_ACP;
+
+      if (!is_read)
+      {
+        is_read = TRUE;
+        if (stream->dwSize >= 3 && !memcmp(stream->buffer, bom_utf8, 3))
+        {
+          cp = CP_UTF8;
+          buf += 3;
+          size -= 3;
+        }
+      }
+
+      nWideChars = MultiByteToWideChar(cp, 0, buf, size, wszText, STREAMIN_BUFFER_SIZE);
       pText = wszText;
     }
     else
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 27f4fee..fa80def 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -5120,10 +5120,10 @@ static void test_EM_STREAMIN(void)
   ok(result == 18, "got %ld, expected %d\n", result, 18);
 
   result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
-  todo_wine ok(result  == 15,
+  ok(result  == 15,
       "EM_STREAMIN: Test UTF8WithBOM returned %ld, expected 15\n", result);
   result = strcmp (buffer,"TestUTF8WithBOM");
-  todo_wine ok(result  == 0,
+  ok(result  == 0,
       "EM_STREAMIN: Test UTF8WithBOM set wrong text: Result: %s\n",buffer);
   ok(es.dwError == 0, "EM_STREAMIN: Test UTF8WithBOM set error %d, expected %d\n", es.dwError, 0);
 




More information about the wine-cvs mailing list