You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by George Storm <gs...@divxcorp.com> on 2007/04/30 01:04:32 UTC

How do I do text manipulation on a property string?

I have a property value (string) that I receive from a command line argument
as lowercase text.

On some platforms I need it to be converted to Title case, on others I need
it to be converted to UPPER case before passing it on to my build tools.

Is there a preferred method to perform case conversions in ant scripts?

Thanks,

- George Lawrence Storm, DivX, Inc.

(Hopefully this is not a duplicate request, it looks like my first message
bounced)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: How do I do text manipulation on a property string?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
Hi,

-----Original Message-----
From: George Storm [mailto:gstorm@divxcorp.com] 
Sent: Monday, April 30, 2007 1:05 AM
To: user@ant.apache.org
Subject: How do I do text manipulation on a property string?

/*
I have a property value (string) that I receive from a command line
argument
as lowercase text.

On some platforms I need it to be converted to Title case, on others I
need
it to be converted to UPPER case before passing it on to my build tools.

Is there a preferred method to perform case conversions in ant scripts?
*/

simply choose a scripting language running in bsf 
(jruby,groovy,javascript,beanshell, jython,judoscript ...)
and use it for string conversion combined with calling ant api

method setProperty() for overwriting an existing property
method setNewPropery for creating a new property

example =

<project name="bla" default="main" basedir=".">
    <!-- // Properties -->
    <property name="myprop" value="foobar"/>
    <!-- Properties // -->

    <target name="depends">

        <script language="ruby">
        <![CDATA[
            $project.setProperty "str.toupper", $myprop.upcase
            $project.setProperty "str.capitalize", $myprop.capitalize
            $project.setProperty "str.chop", $myprop.chop
            $project.setProperty "str.delete", $myprop.delete("o","b")
            $project.setProperty "str.reverse", $myprop.reverse
            $project.setProperty "str.slice", $myprop.slice(3..6)
            
		]]>
        </script>			
        
    </target>

    <target name="main" depends="depends">

    <echoproperties prefix="str" />

    </target>
</project>

main:
[echoproperties] #Ant properties
[echoproperties] #Mon Apr 30 08:33:52 CEST 2007
[echoproperties] str.delete=foobar
[echoproperties] str.reverse=raboof
[echoproperties] str.toupper=FOOBAR
[echoproperties] str.chop=fooba
[echoproperties] str.slice=bar
[echoproperties] str.capitalize=Foobar
BUILD SUCCESSFUL
Total time: 2 seconds


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org