@@ -61,6 +61,9 @@ Other changes: | |||||
removed from the JDK. | removed from the JDK. | ||||
Bugzilla Report 59855 | Bugzilla Report 59855 | ||||
* added a new <native2asciifilter> filter that can perform non-ASCII | |||||
to Unicode-escape conversions. | |||||
Changes from Ant 1.9.6 TO Ant 1.9.7 | Changes from Ant 1.9.6 TO Ant 1.9.7 | ||||
=================================== | =================================== | ||||
@@ -1143,6 +1143,7 @@ and \\. | |||||
<a href="#ignoreblank">IgnoreBlank</a><br> | <a href="#ignoreblank">IgnoreBlank</a><br> | ||||
<a href="#filterdeletecharacters">DeleteCharacters</a><br> | <a href="#filterdeletecharacters">DeleteCharacters</a><br> | ||||
<a href="#uniqfilter">UniqFilter</a><br> | <a href="#uniqfilter">UniqFilter</a><br> | ||||
<a href="#native2asciifilter">Native2AsciiFilter</a><br> | |||||
</p> | </p> | ||||
The following string filters are provided by the optional distribution. | The following string filters are provided by the optional distribution. | ||||
@@ -1487,6 +1488,39 @@ This suppresses duplicate lines. | |||||
</tokenfilter> | </tokenfilter> | ||||
</pre></blockquote> | </pre></blockquote> | ||||
<p><b><em><a name="native2asciifilter">Native2AsciiFilter</a></em></b></p> | |||||
<p>Uses the "builtin" implementation of | |||||
the <a href="../Tasks/native2ascii.html">native2ascii</a> task.</p> | |||||
<p>Replaces non-ascii characters by their Unicode-escapes or | |||||
vice-versa. <em>Since Ant 1.9.8</em>.</p> | |||||
<p>This filter may be used directly within a filterchain.</p> | |||||
<table cellSpacing=0 cellPadding=2 border=1> | |||||
<tr> | |||||
<td vAlign=top><b>Attribute</b></td> | |||||
<td vAlign=top><b>Description</b></td> | |||||
<td vAlign=top align="center"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td vAlign=top>reverse</td> | |||||
<td vAlign=top>Reverse the sense of the conversion, | |||||
i.e. convert from ASCII to native.</td> | |||||
<td vAlign=top align="center">No</td> | |||||
</tr> | |||||
</table> | |||||
<h4>Example:</h4> | |||||
<p>This replaces all non-ASCII characters by their Unicode-escapes.</p> | |||||
<blockquote><pre> | |||||
<tokenfilter> | |||||
<native2asciifilter/> | |||||
</tokenfilter> | |||||
</pre></blockquote> | |||||
<p><b><em><a name="scriptfilter">ScriptFilter</a></em></b></p> | <p><b><em><a name="scriptfilter">ScriptFilter</a></em></b></p> | ||||
This is an optional filter that executes a script in a | This is an optional filter that executes a script in a | ||||
<a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a> | <a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a> | ||||
@@ -140,5 +140,7 @@ | |||||
classname="org.apache.tools.ant.filters.SortFilter"/> | classname="org.apache.tools.ant.filters.SortFilter"/> | ||||
<componentdef name="uniqfilter" onerror="ignore" | <componentdef name="uniqfilter" onerror="ignore" | ||||
classname="org.apache.tools.ant.filters.UniqFilter"/> | classname="org.apache.tools.ant.filters.UniqFilter"/> | ||||
<componentdef name="native2asciifilter" onerror="ignore" | |||||
classname="org.apache.tools.ant.filters.Native2AsciiFilter"/> | |||||
</antlib> | </antlib> | ||||
@@ -0,0 +1,47 @@ | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||||
* contributor license agreements. See the NOTICE file distributed with | |||||
* this work for additional information regarding copyright ownership. | |||||
* The ASF licenses this file to You under the Apache License, Version 2.0 | |||||
* (the "License"); you may not use this file except in compliance with | |||||
* the License. You may obtain a copy of the License at | |||||
* | |||||
* http://www.apache.org/licenses/LICENSE-2.0 | |||||
* | |||||
* Unless required by applicable law or agreed to in writing, software | |||||
* distributed under the License is distributed on an "AS IS" BASIS, | |||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
* See the License for the specific language governing permissions and | |||||
* limitations under the License. | |||||
* | |||||
*/ | |||||
package org.apache.tools.ant.filters; | |||||
import org.apache.tools.ant.util.Native2AsciiUtils; | |||||
/** | |||||
* A filter that performs translations from characters to their | |||||
* Unicode-escape sequences and vice-versa. | |||||
* | |||||
* @since Ant 1.9.8 | |||||
*/ | |||||
public class Native2AsciiFilter extends TokenFilter.ChainableReaderFilter { | |||||
private boolean reverse; | |||||
/** | |||||
* Flag the conversion to run in the reverse sense, | |||||
* that is Ascii to Native encoding. | |||||
* | |||||
* @param reverse True if the conversion is to be reversed, | |||||
* otherwise false; | |||||
*/ | |||||
public void setReverse(boolean reverse) { | |||||
this.reverse = reverse; | |||||
} | |||||
public String filter(String line) { | |||||
return reverse | |||||
? Native2AsciiUtils.ascii2native(line) | |||||
: Native2AsciiUtils.native2ascii(line); | |||||
} | |||||
} |
@@ -0,0 +1,53 @@ | |||||
<?xml version="1.0"?> | |||||
<!-- | |||||
Licensed to the Apache Software Foundation (ASF) under one or more | |||||
contributor license agreements. See the NOTICE file distributed with | |||||
this work for additional information regarding copyright ownership. | |||||
The ASF licenses this file to You under the Apache License, Version 2.0 | |||||
(the "License"); you may not use this file except in compliance with | |||||
the License. You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
--> | |||||
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> | |||||
<import file="../antunit-base.xml" /> | |||||
<target name="testForward"> | |||||
<au:assertTrue> | |||||
<resourcesmatch> | |||||
<string value="\u00e4\u00f6\u00fc=\u00c4\u00d6\u00dc | |||||
\u00df=\u20ac"/> | |||||
<concat> | |||||
<string value="äöü=ÄÖÜ | |||||
ß=€"/> | |||||
<filterchain> | |||||
<native2asciifilter/> | |||||
</filterchain> | |||||
</concat> | |||||
</resourcesmatch> | |||||
</au:assertTrue> | |||||
</target> | |||||
<target name="testReverse"> | |||||
<au:assertTrue> | |||||
<resourcesmatch> | |||||
<string value="äöü=ÄÖÜ | |||||
ß=€"/> | |||||
<concat> | |||||
<string value="\u00e4\u00f6\u00fc=\u00c4\u00d6\u00dc | |||||
\u00df=\u20ac"/> | |||||
<filterchain> | |||||
<native2asciifilter reverse="true"/> | |||||
</filterchain> | |||||
</concat> | |||||
</resourcesmatch> | |||||
</au:assertTrue> | |||||
</target> | |||||
</project> |