Commit cb8c500e authored by Qian Hong's avatar Qian Hong Committed by Alexandre Julliard

riched20: Added support for UTF8 BOM stream.

parent cb082b90
...@@ -283,9 +283,10 @@ static ME_TextBuffer *ME_MakeText(void) { ...@@ -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) static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
{ {
WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
WCHAR *pText; WCHAR *pText;
LRESULT total_bytes_read = 0; LRESULT total_bytes_read = 0;
BOOL is_read = FALSE;
static const char bom_utf8[] = {0xEF, 0xBB, 0xBF};
TRACE("%08x %p\n", dwFormat, stream); TRACE("%08x %p\n", dwFormat, stream);
...@@ -304,8 +305,23 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea ...@@ -304,8 +305,23 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
if (!(dwFormat & SF_UNICODE)) 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 */ WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE); 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; pText = wszText;
} }
else else
......
...@@ -5120,10 +5120,10 @@ static void test_EM_STREAMIN(void) ...@@ -5120,10 +5120,10 @@ static void test_EM_STREAMIN(void)
ok(result == 18, "got %ld, expected %d\n", result, 18); ok(result == 18, "got %ld, expected %d\n", result, 18);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer); 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); "EM_STREAMIN: Test UTF8WithBOM returned %ld, expected 15\n", result);
result = strcmp (buffer,"TestUTF8WithBOM"); result = strcmp (buffer,"TestUTF8WithBOM");
todo_wine ok(result == 0, ok(result == 0,
"EM_STREAMIN: Test UTF8WithBOM set wrong text: Result: %s\n",buffer); "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); ok(es.dwError == 0, "EM_STREAMIN: Test UTF8WithBOM set error %d, expected %d\n", es.dwError, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment