我明白,你想避免螞蟻擴展,但該解決方案使用正則表達式來實現的約束是有點緊 - 道歉,如果該規則太多以下彎曲(休息?)。
,似乎有問題的螞蟻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