Recent

Author Topic: Error in LazStringUtils.SpecialCharsToHex?  (Read 414 times)

dsiders

  • Sr. Member
  • ****
  • Posts: 427
Error in LazStringUtils.SpecialCharsToHex?
« 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.
Lazarus 2.0.12 / 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

lucamar

  • Hero Member
  • *****
  • Posts: 3609
Re: Error in LazStringUtils.SpecialCharsToHex?
« Reply #1 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)
« Last Edit: November 03, 2020, 06:13:35 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dsiders

  • Sr. Member
  • ****
  • Posts: 427
Re: Error in LazStringUtils.SpecialCharsToHex?
« Reply #2 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
Lazarus 2.0.12 / 2.1 (SVN) / FPC 3.0.4 / FPC 3.2.0 / x86-win64 / Windows 8.1

Bart

  • Hero Member
  • *****
  • Posts: 4189
    • Bart en Mariska's Webstek
Re: Error in LazStringUtils.SpecialCharsToHex?
« Reply #3 on: November 03, 2020, 10:35:47 pm »
Hmm, we could also extend Utf8EscapeControlChars() to do just that.

Bart

 

TinyPortal © 2005-2018