mIRC Homepage
Posted By: maroon .pos property $regml() $regmlex() unicode - 20/02/19 08:27 PM
I'm helping rockcavera who first noticed parts of this.

The .pos property for $regml() and $regmlex() are not reporting the correct position when the string contains codepoints above 127.

Code:
//var %msg multibyte character $chr(233) test | echo -a pos: $pos(%msg,test) | noop $regex(%msg,/(test)/u) | echo -a regex: $regml(1).pos


In 7.52 and earlier

returns whether or not /u modifier is used:
pos: 23
regex: 23

In 7.53 and newer

returns whether or not /u modifier is used:
pos: 23
regex: 24

I then checked to see if $regmlex().pos did the same thing, and it does the same as $regml() in both versions. However at first I was having trouble avoiding an error message until discovering that $regmlex() wasn't working without using the <name> parameter even though /help indicates that [name] is optional.
Posted By: Khaled Re: .pos property $regml() $regmlex() unicode - 22/02/19 11:37 AM
Thanks, this issue has been fixed for the next version.
Posted By: maroon Re: .pos property $regml() $regmlex() unicode - 11/03/19 05:15 PM
Looks like the beta fixes the .pos issue in $regml and $remlex. Can you confirm if $regmlex is supposed to require the 'name' parameter instead of being optional as /help says? It's saying invalid parameter until I use the name:

Code:
//var %msg multibyte character $chr(233) test | echo -a pos: $pos(%msg,test) | noop $regex(%msg,/(test)/u) | echo -a regex: $regmlex(default,1).pos

Posted By: Khaled Re: .pos property $regml() $regmlex() unicode - 11/03/19 06:16 PM
Yes, it needs it. $regmlex() has three parameters, two of which are optional, the first and the last. If you only use two parameters, it cannot know which two you've specified.
Posted By: Wims Re: .pos property $regml() $regmlex() unicode - 11/03/19 06:49 PM
That's not correct.

Code:
//noop $regex(abcdefgh,/([a-h])([a-h])/g) | echo -a $regmlex(1,2) $regmlex(2,2)
$regmlex uses the first parameter as the Nth match, which is correct for regex-identifier behaviors. $regmlex is working correctly, it's the first parameter that is optional, the name; the others two are required, you want to access the Nth match and Mth capture for that match.

Edit: seems like the others two are not really required, not a huge fan of the design but if $regmlex(name,N) works, then $regmlex(N) should work the same when applicable
Posted By: maroon Re: .pos property $regml() $regmlex() unicode - 11/03/19 07:06 PM
But my example did use 2 parameters, and $regmlex did know which to use. If only 1 parameter is required, then why did $regmlex(1) fail while $regmlex(default,1) succeeded?

edit: in other words,

$regmlex(default,1).pos works,
$regmlex(default,1,1).pos works

but $regmlex(1).pos using the only parameter that's not optional is failing
Posted By: Khaled Re: .pos property $regml() $regmlex() unicode - 12/03/19 09:48 AM
That is because the identifier is trying to guess which parameters you have specified based on their content. You should always specify the name.

Scripters have often requested that some identifier parameters be optional for the sake of convenience, ie. to decrease typing, make scripts shorter, etc. Unfortunately, the side-effect is that quite a few identifers that support optional parameters have to guess which parameter you've specified based on content. It also makes them more difficult to extend or update. It's not good design and if I could do it without breaking scripts, I would remove optional parameters in many identifiers.

Please note that I will not change how this feature works. It has worked like this for far too long and changing it now could easily break older scipts.
© mIRC Discussion Forums