Author: bayard Date: Thu Jun 25 03:54:43 2009 New Revision: 788244 URL: http://svn.apache.org/viewvc?rev=788244&view=rev Log: Rather than writing specific translators to handle unicode between different ranges, UnicodeEscaper now supports a range filter. cf LANG-505
Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java?rev=788244&r1=788243&r2=788244&view=diff ============================================================================== --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java Thu Jun 25 03:54:43 2009 @@ -25,10 +25,47 @@ */ public class UnicodeEscaper extends CodePointTranslator { + private int below = 0; + private int above = Integer.MAX_VALUE; + private boolean between = true; + + public static UnicodeEscaper below(int codepoint) { + return between(0, codepoint); + } + + public static UnicodeEscaper above(int codepoint) { + return between(codepoint, Integer.MAX_VALUE); + } + + public static UnicodeEscaper outsideOf(int codepointLow, int codepointHigh) { + UnicodeEscaper escaper = new UnicodeEscaper(); + escaper.above = codepointHigh; + escaper.below = codepointLow; + escaper.between = false; + return escaper; + } + + public static UnicodeEscaper between(int codepointLow, int codepointHigh) { + UnicodeEscaper escaper = new UnicodeEscaper(); + escaper.above = codepointHigh; + escaper.below = codepointLow; + return escaper; + } + /** * {...@inheritdoc} */ public boolean translate(int codepoint, Writer out) throws IOException { + if(between) { + if (codepoint < below || codepoint > above) { + return false; + } + } else { + if (codepoint >= below && codepoint <= above) { + return false; + } + } + if (codepoint > 0xffff) { // TODO: Figure out what to do. Output as two unicodes? // Does this make this a Java-specific output class?