ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peterrei...@apache.org>
Subject Re: AW: capitalize first letter of a property?
Date Thu, 15 Jul 2004 12:29:02 GMT
I do now see how the propertyregex example works.

The script example may be nicely written using an ant 1.6 <scriptdef>:
    <scriptdef name="capitalize" language="beanshell">
      <attribute name="input"/>
      <attribute name="property"/>
      // getting the value
      lowercaseValue = attributes.get("input");

      // the first character
      ch = lowercaseValue.substring(0,1);

      // the rest of the value
      rest = lowercaseValue.substring(1);

      // convert first character to uppercase
      up = ch.toUpperCase();

      // concatenate the uppercase with the rest
      uppercaseValue = up + rest;

      // store the result in a new property
      project.setNewProperty(attributes.get("property"), uppercaseValue);
    </scriptdef>

    <capitalize input="abc" property="myprop"/>
    <echo>myprop is ${myprop}</echo>

Peter

Jan.Materne@rzf.fin-nrw.de wrote:

><project name="myProject" basedir="." default="foo">
>    <property name="myprop" value="foo" />
>    <target name="foo">
>        <!-- Using Javascript functions to convert the string -->
>        <script language="javascript"> <![CDATA[
>
>            // getting the value
>            lowercaseValue = myProject.getProperty("myprop");
>
>            // the first character
>            ch = lowercaseValue.substring(0,1);
>
>            // the rest of the value
>            rest = lowercaseValue.substring(1);
>
>            // convert first character to uppercase
>            up = ch.toUpperCase();
>
>            // concatenate the uppercase with the rest
>            uppercaseValue = up + rest;
>
>            // store the result in a new property
>            myProject.setProperty("Myprop",uppercaseValue);
>
>        ]]> </script>
>
>        <!-- Display the values -->
>        <echo>myprop=${myprop}</echo>
>        <echo>Myprop=${Myprop}</echo>
>
>    </target>
></project>
>
>or
>
><?xml version="1.0" encoding="ISO-8859-1"?>
><project name="test" basedir="." default="main">
>    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
>    <target name="main">
>        <property name="foo" value="foo"/>
>        <propertyregex property="FOO" input="${foo}" regexp="[a-z]"
>replace="\0" global="true"/>
>        <echo>foo = ${foo}</echo>
>        <echo>FOO = ${FOO}</echo>
>    </target>
></project>
>
>
>
>Jan
>
>  
>
>>-----Urspr√ľngliche Nachricht-----
>>Von: Mike Norman [mailto:mwnorman@sympatico.ca]
>>Gesendet am: Dienstag, 13. Juli 2004 23:29
>>An: user@ant.apache.org
>>Betreff: capitalize first letter of a property?
>>
>>I have an admittedly-silly requirement that a property:
>>
>>    application=foo
>>
>>also have a corresponding property:
>>
>>    uc_application=Foo
>>
>>So, I have successfully built a regex pattern:
>>
>><property
>>	file="foo.properties"
>>/>
>><loadproperties
>>	srcFile="foo.properties"
>>	>
>>	<filterchain>
>>		<prefixlines
>>			prefix="uc_"
>>		/>
>>	</filterchain>
>>	<filterchain>
>>		<tokenfilter>
>>			<replaceregex
>>				pattern="application=(\w)(.+)"
>>				replace="application=toupper(\1)\2"
>>			/>
>>		</tokenfilter>
>>	</filterchain>
>></loadproperties>
>>
>>However, I can't seem to figure out the 'replace' part. Is there a way
>>to get the first group ('\1' - the letter 'f' in the above case) to
>>be capitalized?
>>
>>Thanks in advance,
>>
>>Mike Norman
>>
>>
>>---------------------------------------------------------------------
>>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


Mime
View raw message