Xreplace bug

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Jan 16, 2009
45
0
#1
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
 
Jan 16, 2009
45
0
#3
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!
 
#5
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
#6
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?
 
#7
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
 
#10
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