[fpc-pascal] Parse unicode scalar

Hairy Pixels genericptr at gmail.com
Mon Jul 3 07:01:11 CEST 2023



> On Jul 3, 2023, at 11:36 AM, Mattias Gaertner via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> Useless array of.
> And it does not return the bytecount.

it's an open array so what's the problem?

> 
>> var
>>  i: Integer;
>>  byteCount: Integer;
>> begin
>>  // Number of bytes required to represent the Unicode scalar
>>  if unicodeScalar < $80 then
>>    byteCount := 1
>>  else if unicodeScalar < $800 then
>>    byteCount := 2
>>  else if unicodeScalar < $10000 then
>>    byteCount := 3
>>  else if unicodeScalar < $110000 then
>>    byteCount := 4
>>  else
>>    raise Exception.Create('Invalid Unicode scalar');
>> 
>>  // Extract the individual bytes using bitwise operations
>>  for i := byteCount - 1 downto 0 do
>>  begin
>>    bytes[i] := $80 or (unicodeScalar and $3F);
> 
> Wrong for byteCount=1

really? How so? 

ChatGPT is risky because it will give wrong information with perfect confidence and there's no way for the ignorant person to know.

Regards,
Ryan Joseph



More information about the fpc-pascal mailing list