From b9ab7659bc45259e459043912a70bf8579774017 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Thu, 25 Jun 2009 03:54:43 +0000 Subject: [PATCH] Rather than writing specific translators to handle unicode between different ranges, UnicodeEscaper now supports a range filter. cf LANG-505 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@788244 13f79535-47bb-0310-9956-ffa450edef68 --- .../lang/text/translate/UnicodeEscaper.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java b/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java index 3214c3356..8983a17f0 100644 --- a/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java +++ b/src/java/org/apache/commons/lang/text/translate/UnicodeEscaper.java @@ -25,10 +25,47 @@ import java.io.Writer; */ 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?