Page 1 of 1

[fixed] Bug in gettokenindex()

Posted: 13 Apr 2023 15:02
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!)

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 10:24
by admin
Debatable. SC gettokenindex() ignores separators that are within quotes.

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 12:40
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?

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 13:15
by admin
Yep, convinced, I'll fix gettokenindex().

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 13:51
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!

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 14:09
by admin
It's coming.

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 15:21
by PeterH
:shock: :tup: :cup:

Re: Bug in gettokenindex()

Posted: 15 Apr 2023 15:27
by PeterH
Oooh - *both* in avail beta :shock: :tup: :appl: :ball:

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

[fiixed] Re: Bug in gettokenindex()

Posted: 15 Apr 2023 16:02
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