Xreplace bug

Jan 16, 2009
45
0
My 4utils64.dll is dated 2-4-16. My TCC is v19.02.37 x64

The following line:
SET record_new=%@XREPLACE[jjjj,\r\n\r\n,%record_new]
produces, where every jjjj was:
rCRLFrCRLF
It should produce
CRLFCRLF
 
May 29, 2008
543
3
Groton, CT
It looks like \n produces both a CR and an LF, and \r produces a literal 'r'.

Dave C.
 
Jan 16, 2009
45
0
Mmmm, good thought.
I tested it, and you're right:
SET record_new=%@XREPLACE[jjjj,\n\n,%record_new]
works correctly.
However, the code I use to set up the substitution is:
SET record_new=%@XREPLACE[\r\n\r\n,jjjj,%record]
which has been working.
If I change it to test your theory, to be:
SET record_new=%@XREPLACE[\n\n,jjjj,%record]
then it does not find any CRLR to substitute.

So Xreplace has a different meaning for \r and \n depending on whether it is the source or the target of the substitution.
Ugh!
 
May 20, 2008
9,975
72
Syracuse, NY, USA
Hmmm! @XREPLACE and @REREPLACE seem to work the same ... maybe a bug in Oniguruma or an oversight. I'll look into it presently.
 
May 20, 2008
9,975
72
Syracuse, NY, USA
New 4UTILS on lucky.syr.edu. That was easy. See before/after below. I recall some collaboration with Rex on XREPLACE/REREPLACE. If they are still similar, than the necessary change is obvious. Here's what WAS in 4UTILS; it needed to be split into two cases.:
Code:
if ( *r == L'n' ) // insert newline
{
   *p++ = L'\r';
   *p++ = L'\n';
   q++;
   continue;
}
BEFORE:

Code:
v:\> set z=1jjjj2jjjj3jjjj4

v:\> set zz=%@xreplace[jjjj,"\r\n\r\n",%z]

v:\> set z
1jjjj2jjjj3jjjj4

v:\> set zz
1r
r
2r
r
3r
r
4
AFTER:

Code:
p:\4utils\release> set z=1jjjj2jjjj3jjjj4

p:\4utils\release> set zz=%@xreplace[jjjj,"\r\n\r\n",%z]

p:\4utils\release> set z
1jjjj2jjjj3jjjj4

p:\4utils\release> set zz
1

2

3

4
 
Jan 16, 2009
45
0
Vince,
I've done regex in Perl (albeit a while ago).
Does Rereplace *require* the use of back reference expressions? Can I do ordinary regex in it?
 
May 20, 2008
9,975
72
Syracuse, NY, USA
Vince,
I've done regex in Perl (albeit a while ago).
Does Rereplace *require* the use of back reference expressions? Can I do ordinary regex in it?
@XREPLACE doesn't *require* back-references (\1, \2, ...). Apparently, neither does @REREPLACE.

Code:
v:\> echo %@rereplace[a,e,bat]
bet

v:\> echo %@xreplace[a,e,bat]
bet
 
May 20, 2008
9,975
72
Syracuse, NY, USA
Then what is the difference between Rereplace and Xreplace?
I don't know if there are any differences. There may be subtle ones. @XREPLACE predates @REREPLACE. I never bothered to remove it from 4UTILS when @REREPLACE arrived.
 
May 20, 2008
9,975
72
Syracuse, NY, USA
Having looked at the code for @XREPLACE, I think there are two features (????) that @REREPLACE doesn't have.

You can limit the number of replacements that are made to N by prefixing <pattern> with N$. And, if any of the parameters are the name of an environment variable prefixed with '@', @XREPLACE will de-reference the envvar. If I recall correctly, that was an attempt to get around strings with troublesome characters in them. Examples:

Code:
v:\> echo %@xreplace[3$i,o,iiiiii]
oooiii

v:\> echo %@xreplace[i,o,@windir]
C:\Wondows