From: Rutger H. <ru...@cs...> - 2003-09-05 00:31:36
|
OK, an update: if I write the property to a file and use <replaceregexp> the behaviour is the same: I must *quadruple* the backslashes in the replace string. Since this appears universal in Ant regexps, I guess it is here to stay. Is it to do with escaping for a pass of interpretation by ant (which halves the number of '\'), then escaping for a pass of interpretation by regexp (again halving the number of '\')? Anyway, since this appears canonical behaviour, I think it is a good idea to document it in ant replaceregexp and cpp-contrib propertyregex. Rutger P.S. One seriously minor nibble: why is the nomenclature of the global flag different in propertyregex and replaceregexp? global="true" <-> flags="g". Rutger Hofman wrote: > Thanks for your effort, to start with! > > Inger, Matthew wrote: > >> You will need to upgrade to ant 1.5.3-1 >> I don't the exact version where it's fixed, but there >> was apparantly a problem with the way substititions were >> being done, where the code was pulling a character beyond >> the end of the string, giving an exception. (The exception >> happens when i run within IntelliJ, which uses it's own >> ANT, but not when i use the 1.5.3-1 version). > > > I run either ant 1.5.4 or ant 1.6alpha, last night's build, > and now I also tried our previously installed version 1.5.3-1. > Same behaviour everywhere. > Besides, does propertyregex really depend on ant i.s.o. the > regexp stuff underlying both ant and ant-contrib, or on its > own ant-contrib stuff? Maybe I have some wrong regexp > package -- though replaceregexp works fine for me. > >> Note: That the "regexp" attribute needs you to double >> the backslash character, as specified by the perl re syntax. >> However, the replacement should be done as is, since it >> is interperated as a literal string, with special processing >> done for the backreference insertion. ANT is not using the >> native substite methods (such as org.apache.regexp.RE.substitute) > > > This does not really match what I see... Also, I cannot believe that > a '\' to be used in replace must not be escaped, since \0, \1 etc > (and I do not know how many more special strings, e.g. \n) are > treated specially. Otherwise, how could replace distinguish between > \0 as "the first ()-ed match" and \0 as the literal string '\0', or > a newline and the string '\n'? > > Rutger > >> <property name="p-in" value="\\abc\\def" /> >> <echo message="${p-in}" /> >> <propertyregex >> property="p-out" >> input="${p-in}" >> regexp="\\\\" >> replace="\" >> global="true" /> > > > (BTW, this implements the reversed substitution from what I intended: it > does "\\" -> "\" i.s.o. "\" -> "\\".) > > This example gives me, for all of ant-1.5.3-1, ant-1.5.4 and ant-1.6alpha: > > init: > [echo] \\abc\\def > > BUILD FAILED > > java.lang.StringIndexOutOfBoundsException: String index out of range: 1 > at java.lang.String.charAt(String.java(Compiled Code)) > at java.util.regex.Matcher.appendReplacement(Matcher.java:543) > at java.util.regex.Matcher.replaceAll(Matcher.java:647) > at > org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp.substitute(Jdk14RegexpRegexp.java:112) > > at net.sf.antcontrib.property.RegexTask.doReplace(Unknown Source) > at net.sf.antcontrib.property.RegexTask.execute(Unknown Source) > at > org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193) > at org.apache.tools.ant.Task.perform(Task.java:341) > at org.apache.tools.ant.Target.execute(Target.java:309) > at org.apache.tools.ant.Target.performTasks(Target.java:336) > at org.apache.tools.ant.Project.executeTarget(Project.java:1339) > at org.apache.tools.ant.Project.executeTargets(Project.java:1255) > at org.apache.tools.ant.Main.runBuild(Main.java:609) > at org.apache.tools.ant.Main.start(Main.java:196) > at org.apache.tools.ant.Main.main(Main.java:235) > > The intended effect is achieved for regexp="\\\\" replace="\\\\", > so in replace the backslash must be *quadrupled*. > Is this different from the behaviour you see? > My system: Linux, RedHat 7.4 (or near that), JAVA_HOME is IBMJava2-14 > or sun j2sdk1.4.2, ant-contrib 0.4 (else, no propertyregex of course) > downloaded today, ant 1.5.3-1, 1.5.4 or 1.6alpha. For completeness, I can > also test under Windows XP (but I will believe in different behaviour > only when I see it :-). > > (BTW, this implements the reversed substitution that I intended: it does > "\\" -> "\" i.s.o. "\" -> "\\".) > > Maybe I should take a look at the code, after all... No problem for sure. > As a first step, I will grab a cvs source distro of cpp-tasks. > > Rutger Hofman > VU Amsterdam > >> ---------------- >> Matthew Inger [in...@sy...] >> Software Developer >> Synygy, Inc >> 610-664-7433 x 7770 >> "Man who jump off cliff, leap to conclusions." - Confucious >> >> >> -----Original Message----- >> From: Rutger Hofman [mailto:ru...@cs...] >> Sent: Thursday, September 04, 2003 1:29 PM >> To: ant...@li... >> Subject: Re: [Ant-contrib-developers] propertyregex: '\' within patterns >> >> >> Why do I have to quadruplate the backslash? Why in replace and >> not in regexp? >> I would expect, to replace '\' with '\\': >> regexp="\\" replace="\\\\" (2 and 4) >> or if I must quadruplate, then I would expect >> regexp="\\\\" replace="\\\\\\\\" (4 and 8) >> >> It is like none of these. Specifying 8 '\' in replace also >> gives the correct result. So, 2 and 8 is OK, as is 2 and 7. >> However, 4 and 8 gives a failure to match the pattern: >> 4 apparently matches 2 '\' in the input string. >> >> (In fact, I would not have been surprised if the seventh >> backslash would have escaped the following end-quote, but ant >> life seems not so simple.) >> >> Greetz, >> >> Rutger Hofman >> VU Amsterdam >> >> Inger, Matthew wrote:> Backslashes should be in increments of two if >> you're >> > actually trying to represent the backslash character. >> > So, you should probably have 8 backslashes. >> > >> > ---------------- >> > Matthew Inger [in...@sy...] >> > Software Developer >> > Synygy, Inc >> > 610-664-7433 x 7770 >> > "Man who jump off cliff, leap to conclusions." - Confucious >> > >> > >> > -----Original Message----- >> > From: Rutger Hofman [mailto:ru...@cs...] >> > Sent: Thursday, September 04, 2003 12:13 PM >> > To: ant...@li... >> > Subject: [Ant-contrib-developers] propertyregex: '\' within patterns >> > >> > >> > Another question about propertyregex. >> > >> > I want to basically set property p-out from replacing >> > "\" with "\\" in some property, p-in. Now, '\' is of >> > course escape character, so I must replace it. I would >> > presume that regexp="\\" and replace="\\\\" would do >> > the job. >> > >> > However, I must do: >> > >> > <propertyregex >> > property="p-out" >> > input="${p-in}" >> > regexp="\\" >> > replace="\\\\\\\" >> > global="true" /> >> > >> > This is, yes, seven(!) backslashes in replace, >> > where I would expect four. >> > >> > Other numbers of backslashes in replace lead to >> > >> > java.lang.StringIndexOutOfBoundsException: String index out of >> range: 3 >> > at java.lang.String.charAt(String.java:460) >> > at >> java.util.regex.Matcher.appendReplacement(Matcher.java:544) >> > >> > or other errors. >> > >> > Any clue? Is this going to be required (and documented) behaviour, >> > or is it a bug? >> > If you want, I can spend some time to hunt down the bug (if my >> professor >> > allows it :-) >> > >> > Rutger >> > >> > >> > >> > >> > ------------------------------------------------------- >> > This sf.net email is sponsored by:ThinkGeek >> > Welcome to geek heaven. >> > http://thinkgeek.com/sf >> > _______________________________________________ >> > Ant-contrib-developers mailing list >> > Ant...@li... >> > https://lists.sourceforge.net/lists/listinfo/ant-contrib-developers >> > >> >> >> >> >> >> ------------------------------------------------------- >> This sf.net email is sponsored by:ThinkGeek >> Welcome to geek heaven. >> http://thinkgeek.com/sf >> _______________________________________________ >> Ant-contrib-developers mailing list >> Ant...@li... >> https://lists.sourceforge.net/lists/listinfo/ant-contrib-developers >> > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Ant-contrib-developers mailing list > Ant...@li... > https://lists.sourceforge.net/lists/listinfo/ant-contrib-developers |