>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?

I would use a <scriptdef>.


Jan

<project>


    <scriptdef name="convert" language="javascript">
        <attribute name="property"/>
        <attribute name="upper"/>
        <attribute name="title"/>
        <element name="fileset" type="fileset"/>
        <![CDATA[
            // 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() +
valueOrg.substring(1);
            
            // 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;
                }
            }
        ]]>
    </scriptdef>


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


</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to