You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Tim Dawson <td...@wamnet.com> on 2001/12/06 21:40:36 UTC

regexp file mapper question - inline replacing

A lot of the examples in
http://jakarta.apache.org/ant/manual/CoreTypes/mapper.html specify how to
grab components of a filename and move them around, add things, etc. 

For example,
<mapper type="regexp" from="^(.*)\.java$$" to="\1.java.bak"/>
foo/bar/B.java -> foo/bar/bar-B.java

<mapper type="regexp" from="^(.*)/([^/]+)/([^/]*)$$" to="\1/\2/\2-\3"/>
foo/bar/B.java -> foo/bar/B.java.bak

<mapper type="regexp" from="^(.*)\.(.*)$$" to="\2.\1"/>
foo/bar/B.java -> java.foo/bar/B

...but what I want to do is a little different. I want to do a
search/replace of a given character... in this case, replace directory
separators with dot files (and while I'm at it, strip an extension).  this
would be easy if I knew how deep the subdirectory tree would always be, but
I don't...

foo/A.txt         -> foo.A
foo/bar/B.txt     -> foo.bar.B
foo/bar/baz/C.txt -> foo.bar.baz.C

I don't quite see how the current from/to attributes for mapper will get me
there, since it seems to need to know up front what you're matching & how
many of them there are, in order to do the substitutions. For example, 

<mapper type="regexp" from="^(.*)/(.*)/(.*)\.txt$$" to="\1.\2.\3"/>
would work for "foo/bar/B.txt" but not for "foo/A.txt" or
"foo/bar/baz/C.txt"

Is there something I'm missing for how to use mapper? Or is the capability
I'm looking for simply not present?

Thanks,

Tim

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: regexp file mapper question - inline replacing

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 6 Dec 2001, Tim Dawson <td...@wamnet.com> wrote:

> Or is the capability I'm looking for simply not present?

I'm afraid the answer is yes.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>