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
This commit is contained in:
Henri Yandell 2009-06-25 03:54:43 +00:00
parent a11f380774
commit b9ab7659bc
1 changed files with 37 additions and 0 deletions

View File

@ -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?