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:
parent
a11f380774
commit
b9ab7659bc
|
@ -25,10 +25,47 @@ import java.io.Writer;
|
||||||
*/
|
*/
|
||||||
public class UnicodeEscaper extends CodePointTranslator {
|
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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public boolean translate(int codepoint, Writer out) throws IOException {
|
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) {
|
if (codepoint > 0xffff) {
|
||||||
// TODO: Figure out what to do. Output as two unicodes?
|
// TODO: Figure out what to do. Output as two unicodes?
|
||||||
// Does this make this a Java-specific output class?
|
// Does this make this a Java-specific output class?
|
||||||
|
|
Loading…
Reference in New Issue