diff --git a/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java b/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java index f5e4835d2..6e9b12e79 100644 --- a/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java +++ b/src/java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java @@ -19,6 +19,9 @@ package org.apache.commons.lang.text.translate; import java.io.IOException; 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 * unicode. @@ -26,13 +29,18 @@ import java.io.Writer; */ public class UnicodeUnescaper extends CharSequenceTranslator { - private boolean escapingPlus = false; + public static enum PARAM { escapePlus }; - public void setEscapingPlus(boolean b) { - this.escapingPlus = b; + private EnumSet params; + + 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 class UnicodeUnescaper extends CharSequenceTranslator { } // consume + symbol in \\u+0045 - if(isEscapingPlus()) { + if(isSet(PARAM.escapePlus)) { if( (index + i < input.length()) && (input.charAt(index + i) == '+') ) { i++; } diff --git a/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java b/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java index d7c3ce290..a6053d8a2 100644 --- a/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java +++ b/src/test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java @@ -36,7 +36,7 @@ public class UnicodeUnescaperTest extends TestCase { // expected } - uu.setEscapingPlus(true); + uu = new UnicodeUnescaper(UnicodeUnescaper.PARAM.escapePlus); assertEquals("Failed to unescape unicode characters with 'u+' notation", "G", uu.translate(input)); }