You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Georg-Johann Lay <Ge...@web.de> on 2009/01/16 20:03:36 UTC
[ant] Determining relative paths resp. substring?
Hi,
can anyone assist me in solving this following quite trivial problem?
Given a path A and the current directory B=. derermine B relative to A.
This is needed for prefixes in zipfileset.
In the special case that I am after B is a subdirectory (of some level)
of A. So gettig the relative path B-A means that A and B look like this:
A=<sting1>
B=<sting1><string2>
I wasted hours to figure out how this could be achieved... The regex
stuff is too complicated because dirs may contain special chars like
blanke, ., \, /, -, $ and even *.
How can I easily remove the prexix A from B? I bet it is a one-liner.
Are there low level string utilities like getting substrings, prefixes, etc?
Thanks in advance,
Georg-Johann
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: [ant] Determining relative paths resp. substring?
Posted by Patrick Martin <an...@gmail.com>.
Hello,
I think you can strip the prefix by using <pathconvert> with a <map>.
Cheers,
Patrick
On Sat, Jan 17, 2009 at 11:32 PM, Georg-Johann Lay <av...@gjlay.de> wrote:
> Georg-Johann Lay schrieb:
>>
>> Hi,
>>
>> can anyone assist me in solving this following quite trivial problem?
>>
>> Given a path A and the current directory B=. derermine B relative to A.
>> This is needed for prefixes in zipfileset.
>>
>> In the special case that I am after B is a subdirectory (of some level) of
>> A. So gettig the relative path B-A means that A and B look like this:
>>
>> A=<sting1>
>> B=<sting1><string2>
>>
>> I wasted hours to figure out how this could be achieved... The regex stuff
>> is too complicated because dirs may contain special chars like blanke, ., \,
>> /, -, $ and even *.
>>
>> How can I easily remove the prexix A from B? I bet it is a one-liner.
>
> Hallo again. Eventuelly the time was not wasted. I am using the following
> code. It is not exactly removing a prefix; it's a little bit more:
>
> <macrodef name="set">
> <attribute name="property" />
> <attribute name="string" />
> <sequential>
> <property name="@{property}" value="@{string}"/>
> </sequential>
> </macrodef>
>
> <tempfile property="prefix.file" />
>
> <macrodef name="unprefix">
> <attribute name="property"/>
> <attribute name="prefix"/>
> <attribute name="string"/>
> <sequential>
> <echo message=".string.suffix.@{property}=!!@{string}"
> file="${prefix.file}" />
> <replace file="${prefix.file}" token="=!!@{prefix}" value="=!!" />
> <replace file="${prefix.file}" token="\" value="/" />
> <replaceregexp file="${prefix.file}" match="//*" replace="/" />
> <replaceregexp file="${prefix.file}" match="=!!/*" replace="=" />
> <property file="${prefix.file}" />
> <property name="@{property}" value="${.string.suffix.@{property}}"/>
> <delete file="${prefix.file}" deleteonexit="true" />
> </sequential>
> </macrodef>
>
> Maybe someone finds is useful.
>
> Grüß, Georg-Johann
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: [ant] Determining relative paths resp. substring?
Posted by Georg-Johann Lay <av...@gjlay.de>.
Georg-Johann Lay schrieb:
> Hi,
>
> can anyone assist me in solving this following quite trivial problem?
>
> Given a path A and the current directory B=. derermine B relative to A.
> This is needed for prefixes in zipfileset.
>
> In the special case that I am after B is a subdirectory (of some level)
> of A. So gettig the relative path B-A means that A and B look like this:
>
> A=<sting1>
> B=<sting1><string2>
>
> I wasted hours to figure out how this could be achieved... The regex
> stuff is too complicated because dirs may contain special chars like
> blanke, ., \, /, -, $ and even *.
>
> How can I easily remove the prexix A from B? I bet it is a one-liner.
Hallo again. Eventuelly the time was not wasted. I am using the
following code. It is not exactly removing a prefix; it's a little bit more:
<macrodef name="set">
<attribute name="property" />
<attribute name="string" />
<sequential>
<property name="@{property}" value="@{string}"/>
</sequential>
</macrodef>
<tempfile property="prefix.file" />
<macrodef name="unprefix">
<attribute name="property"/>
<attribute name="prefix"/>
<attribute name="string"/>
<sequential>
<echo message=".string.suffix.@{property}=!!@{string}"
file="${prefix.file}" />
<replace file="${prefix.file}" token="=!!@{prefix}" value="=!!" />
<replace file="${prefix.file}" token="\" value="/" />
<replaceregexp file="${prefix.file}" match="//*" replace="/" />
<replaceregexp file="${prefix.file}" match="=!!/*" replace="=" />
<property file="${prefix.file}" />
<property name="@{property}"
value="${.string.suffix.@{property}}"/>
<delete file="${prefix.file}" deleteonexit="true" />
</sequential>
</macrodef>
Maybe someone finds is useful.
Grüß, Georg-Johann
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org