Adding escapeXxx(String) and unescapeXxx(String) methods to EscapeUtils + UnescapeUtils, and changing StringEscapeUtils to use them. LANG-505
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@787903 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
adfc17682b
commit
a027b12acf
|
@ -78,7 +78,7 @@ public class StringEscapeUtils {
|
|||
* @return String with escaped values, <code>null</code> if null string input
|
||||
*/
|
||||
public static String escapeJava(String str) {
|
||||
return EscapeUtils.ESCAPE_JAVA.translate(str);
|
||||
return EscapeUtils.escapeJava(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +119,7 @@ public class StringEscapeUtils {
|
|||
* @return String with escaped values, <code>null</code> if null string input
|
||||
*/
|
||||
public static String escapeJavaScript(String str) {
|
||||
return EscapeUtils.ESCAPE_ECMASCRIPT.translate(str);
|
||||
return EscapeUtils.escapeEcmaScript(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,7 +148,7 @@ public class StringEscapeUtils {
|
|||
* @return a new unescaped <code>String</code>, <code>null</code> if null string input
|
||||
*/
|
||||
public static String unescapeJava(String str) {
|
||||
return UnescapeUtils.UNESCAPE_JAVA.translate(str);
|
||||
return UnescapeUtils.unescapeJava(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,7 +182,7 @@ public class StringEscapeUtils {
|
|||
* @return A new unescaped <code>String</code>, <code>null</code> if null string input
|
||||
*/
|
||||
public static String unescapeJavaScript(String str) {
|
||||
return UnescapeUtils.UNESCAPE_ECMASCRIPT.translate(str);
|
||||
return UnescapeUtils.unescapeEcmaScript(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +234,7 @@ public class StringEscapeUtils {
|
|||
* @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code positions</a>
|
||||
*/
|
||||
public static String escapeHtml(String str) {
|
||||
return EscapeUtils.ESCAPE_HTML4.translate(str);
|
||||
return EscapeUtils.escapeHtml4(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -288,7 +288,7 @@ public class StringEscapeUtils {
|
|||
* @see #escapeHtml(Writer, String)
|
||||
*/
|
||||
public static String unescapeHtml(String str) {
|
||||
return UnescapeUtils.UNESCAPE_HTML4.translate(str);
|
||||
return UnescapeUtils.unescapeHtml4(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -355,7 +355,7 @@ public class StringEscapeUtils {
|
|||
* @see #unescapeXml(java.lang.String)
|
||||
*/
|
||||
public static String escapeXml(String str) {
|
||||
return EscapeUtils.ESCAPE_XML.translate(str);
|
||||
return EscapeUtils.escapeXml(str);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -396,7 +396,7 @@ public class StringEscapeUtils {
|
|||
* @see #escapeXml(String)
|
||||
*/
|
||||
public static String unescapeXml(String str) {
|
||||
return UnescapeUtils.UNESCAPE_XML.translate(str);
|
||||
return UnescapeUtils.unescapeXml(str);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -424,7 +424,7 @@ public class StringEscapeUtils {
|
|||
* @since 2.4
|
||||
*/
|
||||
public static String escapeCsv(String str) {
|
||||
return EscapeUtils.ESCAPE_CSV.translate(str);
|
||||
return EscapeUtils.escapeCsv(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -477,7 +477,7 @@ public class StringEscapeUtils {
|
|||
* @since 2.4
|
||||
*/
|
||||
public static String unescapeCsv(String str) {
|
||||
return UnescapeUtils.UNESCAPE_CSV.translate(str);
|
||||
return UnescapeUtils.unescapeCsv(str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,10 @@ public class EscapeUtils {
|
|||
new EscapeLowAsciiAsUnicode(),
|
||||
new EscapeNonAsciiAsUnicode()
|
||||
);
|
||||
|
||||
public static final String escapeJava(String input) {
|
||||
return ESCAPE_JAVA.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator ESCAPE_ECMASCRIPT =
|
||||
new AggregateTranslator(
|
||||
|
@ -53,6 +57,10 @@ public class EscapeUtils {
|
|||
new EscapeNonAsciiAsUnicode()
|
||||
);
|
||||
|
||||
public static final String escapeEcmaScript(String input) {
|
||||
return ESCAPE_ECMASCRIPT.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator ESCAPE_XML =
|
||||
new AggregateTranslator(
|
||||
new LookupTranslator(EntityArrays.BASIC_ESCAPE),
|
||||
|
@ -60,6 +68,10 @@ public class EscapeUtils {
|
|||
new EscapeNonAsciiAsNumericEntity()
|
||||
);
|
||||
|
||||
public static final String escapeXml(String input) {
|
||||
return ESCAPE_XML.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator ESCAPE_HTML3 =
|
||||
new AggregateTranslator(
|
||||
new LookupTranslator(EntityArrays.BASIC_ESCAPE),
|
||||
|
@ -67,6 +79,10 @@ public class EscapeUtils {
|
|||
new EscapeNonAsciiAsNumericEntity()
|
||||
);
|
||||
|
||||
public static final String escapeHtml3(String input) {
|
||||
return ESCAPE_HTML3.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator ESCAPE_HTML4 =
|
||||
new AggregateTranslator(
|
||||
new LookupTranslator(EntityArrays.BASIC_ESCAPE),
|
||||
|
@ -75,8 +91,16 @@ public class EscapeUtils {
|
|||
new EscapeNonAsciiAsNumericEntity()
|
||||
);
|
||||
|
||||
public static final String escapeHtml4(String input) {
|
||||
return ESCAPE_HTML4.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator ESCAPE_CSV = new CsvEscaper();
|
||||
|
||||
public static final String escapeCsv(String input) {
|
||||
return ESCAPE_CSV.translate(input);
|
||||
}
|
||||
|
||||
// TODO: Create a parent class - 'SinglePassTranslator' ?
|
||||
// TODO: It would handle the index checking, and length returning, and
|
||||
// TODO: could also have an optimization check method.
|
||||
|
|
|
@ -47,8 +47,27 @@ public class UnescapeUtils {
|
|||
})
|
||||
);
|
||||
|
||||
public static final String unescapeJava(String input) {
|
||||
return UNESCAPE_JAVA.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = UNESCAPE_JAVA;
|
||||
|
||||
public static final String unescapeEcmaScript(String input) {
|
||||
return UNESCAPE_ECMASCRIPT.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator UNESCAPE_HTML3 =
|
||||
new AggregateTranslator(
|
||||
new LookupTranslator(EntityArrays.BASIC_UNESCAPE),
|
||||
new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE),
|
||||
new NumericEntityUnescaper()
|
||||
);
|
||||
|
||||
public static final String unescapeHtml3(String input) {
|
||||
return UNESCAPE_HTML3.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator UNESCAPE_HTML4 =
|
||||
new AggregateTranslator(
|
||||
new LookupTranslator(EntityArrays.BASIC_UNESCAPE),
|
||||
|
@ -57,6 +76,10 @@ public class UnescapeUtils {
|
|||
new NumericEntityUnescaper()
|
||||
);
|
||||
|
||||
public static final String unescapeHtml4(String input) {
|
||||
return UNESCAPE_HTML4.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator UNESCAPE_XML =
|
||||
new AggregateTranslator(
|
||||
new LookupTranslator(EntityArrays.BASIC_UNESCAPE),
|
||||
|
@ -64,8 +87,16 @@ public class UnescapeUtils {
|
|||
new NumericEntityUnescaper()
|
||||
);
|
||||
|
||||
public static final String unescapeXml(String input) {
|
||||
return UNESCAPE_XML.translate(input);
|
||||
}
|
||||
|
||||
public static final CharSequenceTranslator UNESCAPE_CSV = new CsvUnescaper();
|
||||
|
||||
public static final String unescapeCsv(String input) {
|
||||
return UNESCAPE_CSV.translate(input);
|
||||
}
|
||||
|
||||
static class CsvUnescaper extends CharSequenceTranslator {
|
||||
|
||||
private static final char CSV_DELIMITER = ',';
|
||||
|
|
Loading…
Reference in New Issue