Browse Source

merge r14144 from cpstrnew branch by paul:
call MultiByteToWideChar with dwFlags=0 for UTF8 code page

git-svn-id: trunk@19100 -

paul 14 years ago
parent
commit
233004f72b
1 changed files with 15 additions and 4 deletions
  1. 15 4
      rtl/win/syswin.inc

+ 15 - 4
rtl/win/syswin.inc

@@ -292,6 +292,7 @@ const
   MB_PRECOMPOSED = 1;
   CP_ACP = 0;
   CP_UTF16 = 1200;
+  CP_UTF8 = 65001;
   WC_NO_BEST_FIT_CHARS = $400;
 
 function MultiByteToWideChar(CodePage:UINT; dwFlags:DWORD; lpMultiByteStr:PChar; cchMultiByte:longint; lpWideCharStr:PWideChar;cchWideChar:longint):longint;
@@ -322,15 +323,20 @@ procedure Win32Unicode2AnsiMove(source:punicodechar;var dest:RawByteString;cp :
 procedure Win32Ansi2UnicodeMove(source:pchar;cp : TSystemCodePage;var dest:UnicodeString;len:SizeInt);
   var
     destlen: SizeInt;
+    dwflags: DWORD;
   begin
     // retrieve length including trailing #0
     // not anymore, because this must also be usable for single characters
-    destlen:=MultiByteToWideChar(cp, MB_PRECOMPOSED, source, len, nil, 0);
+    if cp=CP_UTF8 then
+      dwFlags:=0
+    else
+      dwFlags:=MB_PRECOMPOSED;
+    destlen:=MultiByteToWideChar(cp, dwFlags, source, len, nil, 0);
     // this will null-terminate
     setlength(dest, destlen);
     if destlen>0 then
       begin
-        MultiByteToWideChar(cp, MB_PRECOMPOSED, source, len, @dest[1], destlen);
+        MultiByteToWideChar(cp, dwFlags, source, len, @dest[1], destlen);
         PUnicodeRec(pointer(dest)-UnicodeFirstOff)^.CodePage:=CP_UTF16;
       end;
   end;
@@ -377,14 +383,19 @@ procedure Win32Wide2AnsiMove(source:pwidechar;var dest:RawByteString;cp : TSyste
 procedure Win32Ansi2WideMove(source:pchar;cp : TSystemCodePage;var dest:widestring;len:SizeInt);
   var
     destlen: SizeInt;
+    dwFlags: DWORD;
   begin
     // retrieve length including trailing #0
     // not anymore, because this must also be usable for single characters
-    destlen:=MultiByteToWideChar(cp, MB_PRECOMPOSED, source, len, nil, 0);
+    if cp=CP_UTF8 then
+      dwFlags:=0
+    else
+      dwFlags:=MB_PRECOMPOSED;
+    destlen:=MultiByteToWideChar(cp, dwFlags, source, len, nil, 0);
     // this will null-terminate
     setlength(dest, destlen);
     if destlen>0 then
-      MultiByteToWideChar(cp, MB_PRECOMPOSED, source, len, @dest[1], destlen);
+      MultiByteToWideChar(cp, dwFlags, source, len, @dest[1], destlen);
   end;