Replacing the optimisation for LANG-287.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@504334 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f011627264
commit
2ddc45fc77
|
@ -858,9 +858,13 @@ class Entities {
|
||||||
* @return A new escaped <code>String</code>.
|
* @return A new escaped <code>String</code>.
|
||||||
*/
|
*/
|
||||||
public String unescape(String str) {
|
public String unescape(String str) {
|
||||||
|
int firstAmp = str.indexOf('&');
|
||||||
|
if (firstAmp < 0) {
|
||||||
|
return str;
|
||||||
|
} else {
|
||||||
StringWriter stringWriter = createStringWriter(str);
|
StringWriter stringWriter = createStringWriter(str);
|
||||||
try {
|
try {
|
||||||
this.unescape(stringWriter, str);
|
this.doUnescape(stringWriter, str, firstAmp);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// This should never happen because ALL the StringWriter methods called by #escape(Writer, String) do not
|
// This should never happen because ALL the StringWriter methods called by #escape(Writer, String) do not
|
||||||
// throw IOExceptions.
|
// throw IOExceptions.
|
||||||
|
@ -868,6 +872,7 @@ class Entities {
|
||||||
}
|
}
|
||||||
return stringWriter.toString();
|
return stringWriter.toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private StringWriter createStringWriter(String str) {
|
private StringWriter createStringWriter(String str) {
|
||||||
// Make the StringWriter 10% larger than the source String to avoid growing the writer
|
// Make the StringWriter 10% larger than the source String to avoid growing the writer
|
||||||
|
@ -896,8 +901,12 @@ class Entities {
|
||||||
if (firstAmp < 0) {
|
if (firstAmp < 0) {
|
||||||
writer.write(string);
|
writer.write(string);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
doUnescape(writer, string, firstAmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doUnescape(Writer writer, String string, int firstAmp) throws IOException {
|
||||||
writer.write(string, 0, firstAmp);
|
writer.write(string, 0, firstAmp);
|
||||||
int len = string.length();
|
int len = string.length();
|
||||||
for (int i = firstAmp; i < len; i++) {
|
for (int i = firstAmp; i < len; i++) {
|
||||||
|
|
Loading…
Reference in New Issue