Page 1 of 1

[solved] SC formatlist format causes weird side effect

Posted: 16 Nov 2016 23:12
by Filehero
!!!PUT ON HOLD - HAVE TO CHECK ONE MORE THING!!!



Hi,

this is a strange one.

The example code for reproduction.

Code: Select all

  $paths = <<<PATHS
  C:\parent\child\grandchild\1.5.658.3\test.html
  C:\parent\child\grandchild\1.5.658.21\test.html
  C:\parent\child\grandchild\1.5.658.1\test.html
  PATHS;

  $versions = regexmatches($paths, "\d\.\d\.\d{1,3}\.\d{1,3}", <crlf>);
  // sort
  $versions = formatlist($versions, "s", <crlf>);          ***** ISSUE LINE *****
  $newVersion = gettoken($versions, 1, <crlf>);
  // msg($newVersion, 1);
  $match = "<" . regexmatches($paths, "$newVersion.*$") . ">";
  copytext($match);
  msg($match);

With format "s"

Code: Select all

$versions = formatlist($versions, "s", <crlf>);
output is

Code: Select all

<1.5.658.1\test.html>
With format "n"

Code: Select all

$versions = formatlist($versions, "n", <crlf>);
output is

Code: Select all

<1.5.658.1\test.html>
Now with format "r"

Code: Select all

$versions = formatlist($versions, "r", <crlf>);
output all of a sudden has a terminal line break

Code: Select all

<1.5.658.3\test.html
>
Why this crlf just by a different sort order for a regexmatch on an unrelated variable?

:?:

FH

Re: SC formatlist format causes weird side effect

Posted: 16 Nov 2016 23:26
by highend
This has nothing to do with formatlist() :)

It's because of your second regexmatches() line.
Be careful what you match!

Code: Select all

$match = "<" . regexmatches($paths, "$newVersion.*?$") . ">";
Should work fine

Re: SC formatlist format causes weird side effect

Posted: 16 Nov 2016 23:39
by Filehero
Yeah, after I posted it I realized the last line of the input. Regexs are so handy, but everytime I get stuck with one of those special meta characters. :blackstorm: and of course :oops:

Thanks. :)

Can you move it to the tips section please, at least others can benefit from my stupidity?