Sebb pointed out that the implementation for LANG-507 was not thread safe. Rewriting to pass parameters in to the constructor, but doing so in an experimental way - comments very much desired on whether this makes for a nice API or not
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@826514 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b3cec0c2c3
commit
0fd4b3afe1
|
@ -19,6 +19,9 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates escaped unicode values of the form \\u+\d\d\d\d back to
|
* Translates escaped unicode values of the form \\u+\d\d\d\d back to
|
||||||
* unicode.
|
* unicode.
|
||||||
|
@ -26,13 +29,18 @@
|
||||||
*/
|
*/
|
||||||
public class UnicodeUnescaper extends CharSequenceTranslator {
|
public class UnicodeUnescaper extends CharSequenceTranslator {
|
||||||
|
|
||||||
private boolean escapingPlus = false;
|
public static enum PARAM { escapePlus };
|
||||||
|
|
||||||
public void setEscapingPlus(boolean b) {
|
private EnumSet<PARAM> params;
|
||||||
this.escapingPlus = b;
|
|
||||||
|
public UnicodeUnescaper(PARAM... params) {
|
||||||
|
if(params.length > 0) {
|
||||||
|
this.params = EnumSet.copyOf(Arrays.asList(params));
|
||||||
}
|
}
|
||||||
public boolean isEscapingPlus() {
|
}
|
||||||
return this.escapingPlus;
|
|
||||||
|
public boolean isSet(PARAM p) {
|
||||||
|
return (params == null) ? false : params.contains(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +58,7 @@ public int translate(CharSequence input, int index, Writer out) throws IOExcepti
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume + symbol in \\u+0045
|
// consume + symbol in \\u+0045
|
||||||
if(isEscapingPlus()) {
|
if(isSet(PARAM.escapePlus)) {
|
||||||
if( (index + i < input.length()) && (input.charAt(index + i) == '+') ) {
|
if( (index + i < input.length()) && (input.charAt(index + i) == '+') ) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public void testUPlus() {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
uu.setEscapingPlus(true);
|
uu = new UnicodeUnescaper(UnicodeUnescaper.PARAM.escapePlus);
|
||||||
assertEquals("Failed to unescape unicode characters with 'u+' notation", "G", uu.translate(input));
|
assertEquals("Failed to unescape unicode characters with 'u+' notation", "G", uu.translate(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue