You are not logged in.
Pages: 1
Is this code correct? (SynCommons unit)
function RawUnicodeToUtf8(Dest: PUTF8Char; DestLen: PtrInt; Source: PWideChar; SourceLen: PtrInt): PtrInt; overload;
var c: Cardinal;
Tail: PWideChar;
i,j: integer;
begin
result := PtrInt(Dest);
if (Source<>nil) and (Dest<>nil) then begin
// first handle 7 bit ASCII WideChars, by pairs (Sha optimization)
SourceLen := SourceLen*2+PtrInt(Source);
Tail := PWideChar(SourceLen)-2;
if Source<=Tail then
repeat
c := PCardinal(Source)^;
if c and $ff80ff80<>0 then
break; // break on first non ASCII pair
inc(Source,2);
c := c shr 8 or c;
pWord(Dest)^ := c;
inc(Dest,2);
until Source>Tail;
// generic loop, handling one UCS4 char per iteration
Inc(DestLen,PtrInt(Dest));
Shouldn't
Inc(DestLen,PtrInt(Dest));
be placed before the cycle? Now DestLen do not point to real Dest end
Offline
You are right.
Should be fixed by http://synopse.info/fossil/info/fab73a9a7c
Offline
Pages: 1