If i passed UCS2LE string to this function, directly or through ConvertEncoding functions, it should remove LE/BE marks that at beginging of string
functions UCS2LEToUTF8 and UCS2BEToUTF8
i fixed it like this, is it good, to make it patch, or you can fix it in your way
function UCS2BEToUTF8(const s: string): string;
var
len: Integer;
Src: PWord;
Dest: PChar;
i: Integer;
c: Word;
begin
len:=length(s) div 2;
if len=0 then
exit('');
SetLength(Result,len*3);// UTF-8 is at most three times the size
Src:=PWord(Pointer(s));
Dest:=PChar(Result);
for i:=1 to len do begin
c:=BEtoN(Src^);
inc(Src);
if not ((i = 1) and (c = $feff)) then
begin
if ord(c)<128 then begin
Dest^:=chr(c);
inc(Dest);
end else begin
inc(Dest,UnicodeToUTF8SkipErrors(c,Dest));
end;
end;
end;
len:={%H-}PtrUInt(Dest)-PtrUInt(Result);
if len>length(Result) then
raise Exception.Create('');
SetLength(Result,len);
end;
if not ((i = 1) and (c = $feff)) then
is used in both function