diff --git a/WHATSNEW b/WHATSNEW
index 0253e7e59..e79166f2a 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -44,6 +44,9 @@ Other changes:
removed from the JDK.
Bugzilla Report 59855
+ * added a new filter that can perform non-ASCII
+ to Unicode-escape conversions.
+
Changes from Ant 1.9.6 TO Ant 1.9.7
===================================
diff --git a/manual/Types/filterchain.html b/manual/Types/filterchain.html
index 4de10ea3c..90dd74bef 100644
--- a/manual/Types/filterchain.html
+++ b/manual/Types/filterchain.html
@@ -1143,6 +1143,7 @@ and \\.
IgnoreBlank
DeleteCharacters
UniqFilter
+ Native2AsciiFilter
The following string filters are provided by the optional distribution.
@@ -1487,6 +1488,39 @@ This suppresses duplicate lines.
</tokenfilter>
+Native2AsciiFilter
+
+Uses the "builtin" implementation of
+ the native2ascii task.
+
+Replaces non-ascii characters by their Unicode-escapes or
+ vice-versa. Since Ant 1.9.8.
+
+This filter may be used directly within a filterchain.
+
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ reverse |
+ Reverse the sense of the conversion,
+ i.e. convert from ASCII to native. |
+ No |
+
+
+
+Example:
+
+This replaces all non-ASCII characters by their Unicode-escapes.
+
+<tokenfilter>
+ <native2asciifilter/>
+</tokenfilter>
+
+
ScriptFilter
This is an optional filter that executes a script in a
Apache BSF
diff --git a/src/main/org/apache/tools/ant/antlib.xml b/src/main/org/apache/tools/ant/antlib.xml
index b11bac527..64498071a 100644
--- a/src/main/org/apache/tools/ant/antlib.xml
+++ b/src/main/org/apache/tools/ant/antlib.xml
@@ -140,5 +140,7 @@
classname="org.apache.tools.ant.filters.SortFilter"/>
+
diff --git a/src/main/org/apache/tools/ant/filters/Native2AsciiFilter.java b/src/main/org/apache/tools/ant/filters/Native2AsciiFilter.java
new file mode 100644
index 000000000..2e764ae92
--- /dev/null
+++ b/src/main/org/apache/tools/ant/filters/Native2AsciiFilter.java
@@ -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);
+ }
+}
diff --git a/src/tests/antunit/filters/native2ascii-test.xml b/src/tests/antunit/filters/native2ascii-test.xml
new file mode 100644
index 000000000..37074a434
--- /dev/null
+++ b/src/tests/antunit/filters/native2ascii-test.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+