Lazarus

Programming => Packages and Libraries => LazUtils => Topic started by: dsiders on November 03, 2020, 05:52:39 pm

Title: Error in LazStringUtils.SpecialCharsToHex?
Post by: dsiders on November 03, 2020, 05:52:39 pm
I stumbled across this recently...

The name of the routine implies it converts special characters to hexadecimal character constants. It does not.

It uses decimal (%d in its Format argument instead of %x). And converts to #ddd notation instead of #$xx.

Just looking for confirmation before filing a bug report.
Title: Re: Error in LazStringUtils.SpecialCharsToHex?
Post by: lucamar on November 03, 2020, 06:11:12 pm
I can confirm. Something like:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   AString: AnsiString;
  4.   i: Integer;
  5. begin
  6.   AString := '';
  7.   for i := 0 to 64 do
  8.     AString := AString + Chr(i);
  9.   Memo1.Lines.Text := SpecialCharsToHex(AString);
  10. end;
produces:
Code: Text  [Select][+][-]
  1. #0#1#2#3#4#5#6#7#8#9#10#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#27#28#29#30#31 !"#$%&'() ....

(Lazarus 2.0.10/FPC 3.2.0 x86_64-Linux-gtk2)
Title: Re: Error in LazStringUtils.SpecialCharsToHex?
Post by: dsiders on November 03, 2020, 06:28:39 pm
I can confirm. Something like:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   AString: AnsiString;
  4.   i: Integer;
  5. begin
  6.   AString := '';
  7.   for i := 0 to 64 do
  8.     AString := AString + Chr(i);
  9.   Memo1.Lines.Text := SpecialCharsToHex(AString);
  10. end;
produces:
Code: Text  [Select][+][-]
  1. #0#1#2#3#4#5#6#7#8#9#10#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#27#28#29#30#31 !"#$%&'() ....

(Lazarus 2.0.10/FPC 3.2.0 x86_64-Linux-gtk2)

Thanks Lucamar.

Submitted: https://bugs.freepascal.org/view.php?id=38029
Title: Re: Error in LazStringUtils.SpecialCharsToHex?
Post by: Bart on November 03, 2020, 10:35:47 pm
Hmm, we could also extend Utf8EscapeControlChars() to do just that.

Bart
TinyPortal © 2005-2018