ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Dawson <tdaw...@wamnet.com>
Subject regexp file mapper question - inline replacing
Date Thu, 06 Dec 2001 20:40:36 GMT
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:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message