我明白,你想避免蚂蚁扩展,但该解决方案使用正则表达式来实现的约束是有点紧 - 道歉,如果该规则太多以下弯曲(休息?)。
,似乎有问题的蚂蚁XML来实现蚂蚁附带一个JavaScript引擎,这些天,所以任何事情都有可能通常在scriptdef
被藏起来。下面是四个案例变化。
对于您的情况,您将获取some_property
属性并通过upper
脚本处理该脚本以获取要在replaceregexp
任务中使用的字符串的大写版本。
<scriptdef language="javascript" name="upper">
<attribute name="string" />
<attribute name="to" />
project.setProperty(attributes.get("to"),
attributes.get("string").toUpperCase());
</scriptdef>
<scriptdef language="javascript" name="lower">
<attribute name="string" />
<attribute name="to" />
project.setProperty(attributes.get("to"),
attributes.get("string").toLowerCase());
</scriptdef>
<scriptdef language="javascript" name="ucfirst">
<attribute name="string" />
<attribute name="to" />
var the_string = attributes.get("string");
project.setProperty(attributes.get("to"),
the_string.substr(0,1).toUpperCase() + the_string.substr(1));
</scriptdef>
<scriptdef language="javascript" name="capitalize">
<attribute name="string" />
<attribute name="to" />
var s = new String(attributes.get("string"));
project.setProperty(attributes.get("to"),
s.toLowerCase().replace(/^.|\s\S/g,
function(a) { return a.toUpperCase(); }));
</scriptdef>
实施例使用:
<property name="phrase" value="the quick brown FOX jUmped oVer the laZy DOG" />
<upper string="${phrase}" to="upper" />
<lower string="${phrase}" to="lower" />
<ucfirst string="${phrase}" to="ucfirst" />
<capitalize string="${phrase}" to="capitalize" />
<echo message="upper(${phrase})${line.separator}= '${upper}'" />
<echo message="lower(${phrase})${line.separator}= '${lower}'" />
<echo message="ucfirst(${phrase})${line.separator}= '${ucfirst}'" />
<echo message="capitalize(${phrase})${line.separator}= '${capitalize}'" />
和输出:
[echo] upper(the quick brown FOX jUmped oVer the laZy DOG)
[echo] = 'THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'
[echo] lower(the quick brown FOX jUmped oVer the laZy DOG)
[echo] = 'the quick brown fox jumped over the lazy dog'
[echo] ucfirst(the quick brown FOX jUmped oVer the laZy DOG)
[echo] = 'The quick brown FOX jUmped oVer the laZy DOG'
[echo] capitalize(the quick brown FOX jUmped oVer the laZy DOG)
[echo] = 'The Quick Brown Fox Jumped Over The Lazy Dog'
由于波尼和Marco Demaio为implementation of the Capitalization 。
知道约
您可以使用类似于
SCriptdef
任何方便的语言的东西。这里以JavaScript为例。你也可以使用其他的。
来源
2013-11-28 11:21:39