Skip to content

Commit

Permalink
Fixing documentation post translate move to Range API
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1090522 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Henri Yandell committed Apr 9, 2011
1 parent 1a11451 commit f08d8a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public static final String unescapeHtml3(String input) {
* <p>Note that unicode characters greater than 0x7f are as of 3.0, no longer
* escaped. If you still wish this functionality, you can achieve it
* via the following:
* {@code StringEscapeUtils.ESCAPE_XML.with( UnicodeEscaper.above(0x7f) );}</p>
* {@code StringEscapeUtils.ESCAPE_XML.with( new UnicodeEscaper(Range.between(0x7f, Integer.MAX_VALUE)) );}</p>
*
* @param input the {@code String} to escape, may be null
* @return a new escaped {@code String}, {@code null} if null string input
Expand Down
9 changes: 7 additions & 2 deletions src/site/xdoc/article3_0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,16 @@ available in the <a href="userguide.html#lang.concurrent.">user guide</a>.</p>
</pre>
<p>Here we see that <code>ESCAPE_XML</code> is a '<code>CharSequenceTranslator</code>', which in turn is made up of two lookup translators based on the basic XML escapes and another to escape apostrophes. This shows one way to combine translators. Another can be shown by looking at the example to achieve the old XML escaping functionality (escaping non-ASCII): </p>
<pre>
StringEscapeUtils.ESCAPE_XML.with( UnicodeEscaper.above(0x7f) );
StringEscapeUtils.ESCAPE_XML.with( new UnicodeEscaper(Range.between(0x7f, Integer.MAX_VALUE) ) );
</pre>
<p>That takes the standard Commons Lang provided escape functionality, and adds on another translation layer. Another JIRA requested option was to also escape non-printable ASCII, this is now achievable with a modification of the above: </p>
<pre>
StringEscapeUtils.ESCAPE_XML.with( UnicodeEscaper.outsideOf(32, 0x7f) );
StringEscapeUtils.ESCAPE_XML.with(
new AggregateTranslator(
new UnicodeEscaper(Range.between(0, 31)),
new UnicodeEscaper(Range.between(0x80, Integer.MAX_VALUE))
)
)
</pre>
<p>You can also implement your own translators (be they for escaping, unescaping or some aspect of your own). See the <code>CharSequenceTranslator</code> and its <code>CodePointTranslator</code> helper subclass for details - primarily a case of implementing the translate(CharSequence, int, Writer);int method. </p>
</section>
Expand Down

0 comments on commit f08d8a2

Please sign in to comment.