* fixed UTF8Decode for JVM:

o pass length of result array as maximum length instead of that of an empty
     string
   o the returned length of Utf8ToUnicode() includes a terminating #0 char,
     subtract that again when creating a new unicode string with the
     characters

git-svn-id: trunk@33157 -
This commit is contained in:
Jonas Maebe 2016-03-05 15:32:15 +00:00
parent 74eb0de460
commit 599426f2f0

View File

@ -794,18 +794,15 @@ function UTF8Encode(const s : UnicodeString) : RawByteString;
function UTF8Decode(const s : RawByteString): UnicodeString; function UTF8Decode(const s : RawByteString): UnicodeString;
var var
i : SizeInt; i : SizeInt;
hs : UnicodeString;
chars: array of widechar; chars: array of widechar;
begin begin
result:=''; result:='';
if s='' then if s='' then
exit; exit;
SetLength(chars,length(s)); SetLength(chars,length(s)+1);
i:=Utf8ToUnicode(pwidechar(chars),length(hs)+1,pchar(s),length(s)); i:=Utf8ToUnicode(pwidechar(chars),length(s)+1,pchar(s),length(s));
if i>0 then if i>0 then
begin result:=JLString.Create(chars,0,i-1);
result:=JLString.Create(chars,0,i);
end;
end; end;