Fix to MultiByteToWideChar for non-Windows to handle UTF8.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1423 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
macpgmr
2011-01-04 01:08:10 +00:00
parent e9da76ca95
commit 19b0a96386

View File

@ -655,12 +655,20 @@ begin
SetLength(s, cchMultiByte);
Move(lpMultiByteStr^, s[1], cchMultiByte);
end;
SetLength(w, Succ(Length(s)));
StringToWideChar(s, PWideChar(w), Length(w));
{Look for terminating null to determine length of returned string}
Result := 0;
while w[Succ(Result)] <> #0 do
Inc(Result);
if CodePage = CP_UTF8 then
begin
w := UTF8Decode(s);
Result := Length(w);
end
else //TODO: Convert other codepages to UTF8 encoding (see styleun.pas and lconvencoding.pas).
begin
SetLength(w, Succ(Length(s)));
StringToWideChar(s, PWideChar(w), Length(w));
{Look for terminating null to determine length of returned string}
Result := 0;
while w[Succ(Result)] <> #0 do
Inc(Result);
end;
if cchMultiByte < 0 then {Include terminating null too?}
Inc(Result);
if cchWideChar > 0 then {Okay to return string?}