あなたはAntの拡張を避けたいと思っていますが、regexを使ってソリューションを実装するという制約は少し厳しいです。あまりにも多くのルールが崩れると謝罪します。
Antは最近、javascriptエンジンとともに出荷されています。したがって、Ant xmlに実装するのに問題があるようなものは、通常scriptdef
に隠すことができます。以下は、ケースを変更する4つです。
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}'" />
そして出力:implementation of the Capitalization ためポニとマルコDemaioへ
[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'
感謝。
引数の受け渡しをサポートしていないと思われる
SCriptdef
などの便利な言語を使用できます。ここではJavaScriptを例に挙げています。他のものを使うこともできます。
出典
2013-11-28 11:21:39