Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-11

IsAccel bug?

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hans-Peter Diettrich

In forms.IsAccel I suspect an bug, which manifests in very rare cases only:

   position := UTF8Pos(AmpersandChar, ACaption);
This is the position of the &

...

       UTF8Delete(ACaption, 1, position+1);

This IMO removes the character *after* the ampersand, so that

       position := UTF8Pos(AmpersandChar, ACaption);

finds the same & over and over again, while it should find the next one.

Now for some questionable constructs:

A simple Pos would be sufficient, because '&' is an ASCII character.

It would be sufficient to replace the found '&' by something else, in place.

Or a loop until the last char could be used, which eliminates any string time and memory consuming string manipulation.

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich

?

Hans-Peter Diettrich hat am 17. November 2011 um 09:33 geschrieben:

Show quoted text 10 lines
In forms.IsAccel I suspect an bug, which manifests in very rare cases only: ? ? position := UTF8Pos(AmpersandChar, ACaption); This is the position of the & ... ? ? ? ? UTF8Delete(ACaption, 1, position+1); This IMO removes the character *after* the ampersand?

Yes, which is another ampersand (&&). So it deletes both ampersands.? ?
?

, so that> ? ? ? ? position := UTF8Pos(AmpersandChar, ACaption); finds the same & over and over again, while it should find the next one.?

Have you tested it? It looks correct to me.?
?
?

Show quoted text 5 lines
Now for some questionable constructs: A simple Pos would be sufficient, because '&' is an ASCII character.?

Yes. The whole UTF8 in there unneeded, except for the comparison of the one character with the VK.?
?

Show quoted text 5 lines
It would be sufficient to replace the found '&' by something else, in place. Or a loop until the last char could be used, which eliminates any string time and memory consuming string manipulation.?

Feel free to provide a patch.
?
?
Mattias
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111117/44516b53/attachment.html>

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner
Show quoted text 18 lines
Hans-Peter Diettrich hat am 17. November 2011 um 09:33 geschrieben: > In forms.IsAccel I suspect an bug, which manifests in very rare cases only: > > position := UTF8Pos(AmpersandChar, ACaption); > This is the position of the & > > ... > > UTF8Delete(ACaption, 1, position+1); > > This IMO removes the character *after* the ampersand Yes, which is another ampersand (&&). So it deletes both ampersands.

Right :-)

DoDi

Reply by email

Bart
to Hans-Peter Diettrich: In forms.IsAccel I suspect an bug, which manifests in very rare cases only: position :=…
Hans-Peter Diettrich wrote 10 lines
In forms.IsAccel I suspect an bug, which manifests in very rare cases only: position := UTF8Pos(AmpersandChar, ACaption); This is the position of the & ... UTF8Delete(ACaption, 1, position+1); This IMO removes the character *after* the ampersand, so that

Doesn't this remove all charactres starting at position 1 up to and including the first char after the ampersand?

Bart

Reply by email

Hans-Peter Diettrich
to Bart
Show quoted text 14 lines
On 11/17/11, Hans-Peter Diettrich wrote: > In forms.IsAccel I suspect an bug, which manifests in very rare cases only: > > position := UTF8Pos(AmpersandChar, ACaption); > This is the position of the & > > ... > > UTF8Delete(ACaption, 1, position+1); > > This IMO removes the character *after* the ampersand, so that Doesn't this remove all charactres starting at position 1 up to and including the first char after the ampersand?

Lacking any documentation I only can guess what UTF8Delete does :-(

DoDi

Reply by email

Bart
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote
Lacking any documentation I only can guess what UTF8Delete does :-(

Tested Utf8Delete(), and it does as I said, which in the shown code-snippet seems wrong to me, it looks like StartCharIndex and CharCount were swapped?

Bart

Reply by email

cobines
to Bart

2011/11/20 Bart :

Tested Utf8Delete(), and it does as I said, which in the shown code-snippet seems wrong to me, it looks like StartCharIndex and CharCount ?were swapped?

I think it deletes everything up to and including the two ampersands so that it can use UTF8Pos to scan for the next ampersand. So it seems OK.

cobines

Reply by email

Bart
to cobines
cobines wrote
I think it deletes everything up to and including the two ampersands so that it can use UTF8Pos to scan for the next ampersand. So it seems OK.

I didn't see enough of the context then.
My bad.

Bart

Reply by email