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>.
|
||||
*/
|
||||
public String unescape(String str) {
|
||||
int firstAmp = str.indexOf('&');
|
||||
if (firstAmp < 0) {
|
||||
return str;
|
||||
} else {
|
||||
StringWriter stringWriter = createStringWriter(str);
|
||||
try {
|
||||
this.unescape(stringWriter, str);
|
||||
this.doUnescape(stringWriter, str, firstAmp);
|
||||
} catch (IOException e) {
|
||||
// This should never happen because ALL the StringWriter methods called by #escape(Writer, String) do not
|
||||
// throw IOExceptions.
|
||||
|
@ -868,6 +872,7 @@ class Entities {
|
|||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private StringWriter createStringWriter(String str) {
|
||||
// Make the StringWriter 10% larger than the source String to avoid growing the writer
|
||||
|
@ -896,8 +901,12 @@ class Entities {
|
|||
if (firstAmp < 0) {
|
||||
writer.write(string);
|
||||
return;
|
||||
} else {
|
||||
doUnescape(writer, string, firstAmp);
|
||||
}
|
||||
}
|
||||
|
||||
private void doUnescape(Writer writer, String string, int firstAmp) throws IOException {
|
||||
writer.write(string, 0, firstAmp);
|
||||
int len = string.length();
|
||||
for (int i = firstAmp; i < len; i++) {
|
||||
|
|
Loading…
Reference in New Issue