commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r504334 - /jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
Date Tue, 06 Feb 2007 22:25:58 GMT
Author: bayard
Date: Tue Feb  6 14:25:57 2007
New Revision: 504334

URL: http://svn.apache.org/viewvc?view=rev&rev=504334
Log:
Replacing the optimisation for LANG-287. 

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java?view=diff&rev=504334&r1=504333&r2=504334
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Entities.java Tue Feb
 6 14:25:57 2007
@@ -858,15 +858,20 @@
      * @return A new escaped <code>String</code>.
      */
     public String unescape(String str) {
-        StringWriter stringWriter = createStringWriter(str);
-        try {
-            this.unescape(stringWriter, str);
-        } catch (IOException e) {
-            // This should never happen because ALL the StringWriter methods called by #escape(Writer,
String) do not
-            // throw IOExceptions.
-            throw new UnhandledException(e);
+        int firstAmp = str.indexOf('&');
+        if (firstAmp < 0) {
+            return str;
+        } else {
+            StringWriter stringWriter = createStringWriter(str);
+            try {
+                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.
+                throw new UnhandledException(e);
+            }
+            return stringWriter.toString();
         }
-        return stringWriter.toString();
     }
 
     private StringWriter createStringWriter(String str) {
@@ -896,8 +901,12 @@
         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++) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message