[fixed] Bug in gettokenindex()

Things you’d like to miss in the future...
Forum rules
:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:

:info: Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".

:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

[fixed] Bug in gettokenindex()

Post by PeterH »

gettokenindex() (at least with sep=<crlf>) will return the wrong token-(= line-)number, if a "string" (it's *not* XY-syntax!) before the searched token is continued over 2 lines.
Example:

Code: Select all

//§ Test GetTokenIndex()
"Test"
   $lines = <<<#>>>
gd
eins1   <- line 2: OK
gfhjh
lines "with
continued" string
zwei2   <- line 6: NOK
jhgh
xfhg
drei3   <- line 9: NOK
#>>>;

   $x1 = gettokenindex("eins*", $lines, <crlf>, 'iw');
   $x2 = gettokenindex("zwei*", $lines, <crlf>, 'iw');
   $x3 = gettokenindex("drei*", $lines, <crlf>, 'iw');

   echo "x1 | 2 | 3 = $x1 | $x2 | $x3<crlf>Should be 2 | 6 | 9";

And a related wish: gettokenindex() should have a starting-position, like e.g. strpos() has.
If I scan a (much larger!) file like above e.g. for section numbers, I should be able to start scan n+1 with the found position of scan n. But now all scans will/must restart at pos 1.
Very bad: if there's a table of contents - all section numbers will be found there - I can't scan for the real section. :cry:
(What I'm going to code won't work without that!)
Last edited by PeterH on 15 Apr 2023 16:03, edited 1 time in total.

admin
Site Admin
Posts: 66573
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug in gettokenindex()

Post by admin »

Debatable. SC gettokenindex() ignores separators that are within quotes.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in gettokenindex()

Post by PeterH »

OK - then there would be a bug in gettoken() :ninja:
As, when you find a token with gettokenindex(), and then get that token with gettoken(), you get the wrong one.
And from the meaning of the scanned text it even would not meet syntax of .xys - as this is not an allowed situation.

So you should either meet the meaning of token: the text between 2 separators, or add an operand to define the syntax of the scanned text. And take care that the logic of gettokenindex() and gettoken() fit together.
Especially, if the text is text (pun intended), and the goal is to get a line.
(A line is a line is a line - pedantry again, and with reason, again.)

Debated enough?

admin
Site Admin
Posts: 66573
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug in gettokenindex()

Post by admin »

Yep, convinced, I'll fix gettokenindex().

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in gettokenindex()

Post by PeterH »

admin wrote: 15 Apr 2023 13:15 Yep, convinced, I'll fix gettokenindex().
Fine :tup:

A word to "related wish: gettokenindex() should have a starting-position" ?
It's missing badly!

admin
Site Admin
Posts: 66573
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug in gettokenindex()

Post by admin »

It's coming.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in gettokenindex()

Post by PeterH »

:shock: :tup: :cup:

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Bug in gettokenindex()

Post by PeterH »

Oooh - *both* in avail beta :shock: :tup: :appl: :ball:

1) have a problem with smilies :whistle:
2) must go to test :biggrin:

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

[fiixed] Re: Bug in gettokenindex()

Post by PeterH »

OK: what I named a bug is fiixed! :tup:
(Easy to test, as the script stumbled here.)

Now *I* have a problem with an anomaly in the scanned fiile. Must recognize and handle...

And then, for using//testing the new start=, further programming has to be done...

Much work to do, so:

Thanks! :appl: :D

Post Reply