ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: How do I do text manipulation on a property string?
Date Mon, 30 Apr 2007 06:17:03 GMT
>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
>build tools.
>Is there a preferred method to perform case conversions in ant scripts?

I would use a <scriptdef>.



    <scriptdef name="convert" language="javascript">
        <attribute name="property"/>
        <attribute name="upper"/>
        <attribute name="title"/>
        <element name="fileset" type="fileset"/>
            // Access to <attribute>s with default values
            property = attributes.get("property");
            upper    = getDefault("upper", property + ".upper");
            title    = getDefault("title", property + ".title");
            // compute the new values
            valueOrg = project.getProperty(property);
            valueUpc = valueOrg.toUpperCase();
            valueTit = valueOrg.substring(0,1).toUpperCase() +
            // store the values
            project.setNewProperty(upper, valueUpc);
            project.setNewProperty(title, valueTit);
            // Helper function 
            function getDefault(propName, defaultValue) {
                x = attributes.get(propName);
                if (x == null) {
                    return defaultValue; 
                } else {
                    return x;

    <property name="one" value="one"/>
    <property name="two" value="two"/>
    <convert property="one" upper="upper" title="title"/>
        one    : ${one}
        upper  : ${upper}
        title  : ${title}
    <convert property="two"/>
    <echoproperties prefix="two"/>


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message