From 19b0a96386364f6f4e76c0eea29499fee1ee3368 Mon Sep 17 00:00:00 2001 From: macpgmr Date: Tue, 4 Jan 2011 01:08:10 +0000 Subject: [PATCH] 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 --- components/thtmlport/package/htmlmisc.pas | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/components/thtmlport/package/htmlmisc.pas b/components/thtmlport/package/htmlmisc.pas index c125d5331..892f48c4a 100755 --- a/components/thtmlport/package/htmlmisc.pas +++ b/components/thtmlport/package/htmlmisc.pas @@ -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?}