Hi
{$ifdef FPC_HAS_FEATURE_DYNARRAYS}
procedure UCS4Encode(p: PWideChar; len: sizeint; out res: UCS4String);
var
i, reslen: sizeint;
w: longint;
begin
reslen:=0;
i:=0;
{ calculate required length }this func loops over the buffer 2 times. 1) find len in UCS4 chars, 2) make UCS4 contents. Maybe make one loop only? Ie- a) SetLength for result to the len of source. b) single loop: copy content and also calculate real len. c) adjust (decrease) result len, if surrogate pairs were found (N pairs -> decrease by N)
Regards,
Alexey
