Refactoring the array of Java ctrl characters to be in EntityArray rather than embedded in their own escape/unescape

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@795596 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-07-19 19:15:14 +00:00
parent dff12292a0
commit 784e93e61d
3 changed files with 15 additions and 23 deletions

View File

@ -349,6 +349,18 @@ public class EntityArrays {
public static String[][] APOS_UNESCAPE() { return APOS_UNESCAPE.clone(); }
private static final String[][] APOS_UNESCAPE = invert(APOS_ESCAPE);
public static String[][] JAVA_CTRL_CHARS_ESCAPE() { return JAVA_CTRL_CHARS_ESCAPE.clone(); }
private static final String[][] JAVA_CTRL_CHARS_ESCAPE = {
{"\b", "\\b"},
{"\n", "\\n"},
{"\t", "\\t"},
{"\f", "\\f"},
{"\r", "\\r"}
};
public static String[][] JAVA_CTRL_CHARS_UNESCAPE() { return JAVA_CTRL_CHARS_UNESCAPE.clone(); }
private static final String[][] JAVA_CTRL_CHARS_UNESCAPE = invert(JAVA_CTRL_CHARS_ESCAPE);
/**
* Used to invert an escape array into an unescape array
* @param array String[][] to be inverted

View File

@ -29,23 +29,13 @@ import org.apache.commons.lang.CharUtils;
*/
public class EscapeUtils {
public static final CharSequenceTranslator ESCAPE_JAVA_CTRL_CHARS =
new LookupTranslator(
new String[][] {
{"\b", "\\b"},
{"\n", "\\n"},
{"\t", "\\t"},
{"\f", "\\f"},
{"\r", "\\r"}
});
public static final CharSequenceTranslator ESCAPE_JAVA =
new LookupTranslator(
new String[][] {
{"\"", "\\\""},
{"\\", "\\\\"},
}).with(
ESCAPE_JAVA_CTRL_CHARS
new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE())
).with(
UnicodeEscaper.outsideOf(32, 0x7f)
);
@ -63,7 +53,7 @@ public class EscapeUtils {
{"\\", "\\\\"},
{"/", "\\/"}
}),
ESCAPE_JAVA_CTRL_CHARS,
new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE()),
UnicodeEscaper.outsideOf(32, 0x7f)
);

View File

@ -29,21 +29,11 @@ import org.apache.commons.lang.CharUtils;
*/
public class UnescapeUtils {
public static final CharSequenceTranslator UNESCAPE_JAVA_CTRL_CHARS =
new LookupTranslator(
new String[][] {
{"\\b", "\b"},
{"\\n", "\n"},
{"\\t", "\t"},
{"\\f", "\f"},
{"\\r", "\r"}
});
// throw "illegal character: \92" as an Exception if a \ on the end of the Java (as per the compiler)?
public static final CharSequenceTranslator UNESCAPE_JAVA =
new AggregateTranslator(
new UnicodeUnescaper(),
UNESCAPE_JAVA_CTRL_CHARS,
new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_UNESCAPE()),
new LookupTranslator(
new String[][] {
{"\\\\", "\\"},