commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1142151 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/ main/java/org/apache/commons/lang3/text/translate/ test/java/org/apache/commons/lang3/text/translate/
Date Sat, 02 Jul 2011 04:06:23 GMT
Author: bayard
Date: Sat Jul  2 04:06:23 2011
New Revision: 1142151

URL: http://svn.apache.org/viewvc?rev=1142151&view=rev
Log:
Reverting r1090111 - moving the text.translate escapers back from using Range to replicating
parts of the Range API. See the list for details ('unnecessary boxing in StringEscapeUtils
etc'), the move to Range was an uncomfortable fit. 

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringEscapeUtils.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringEscapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringEscapeUtils.java?rev=1142151&r1=1142150&r2=1142151&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringEscapeUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringEscapeUtils.java
Sat Jul  2 04:06:23 2011
@@ -57,10 +57,7 @@ public class StringEscapeUtils {
           }).with(
             new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE())
           ).with(
-            new AggregateTranslator(
-                new UnicodeEscaper(Range.between(0, 31)), 
-                new UnicodeEscaper(Range.between(0x80, Integer.MAX_VALUE)) 
-            )
+            UnicodeEscaper.outsideOf(32, 0x7f) 
         );
 
     /**
@@ -82,10 +79,7 @@ public class StringEscapeUtils {
                             {"/", "\\/"}
                       }),
             new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE()),
-            new AggregateTranslator(
-                new UnicodeEscaper(Range.between(0, 31)), 
-                new UnicodeEscaper(Range.between(0x80, Integer.MAX_VALUE)) 
-            )
+            UnicodeEscaper.outsideOf(32, 0x7f) 
         );
             
     /**

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java?rev=1142151&r1=1142150&r2=1142151&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
Sat Jul  2 04:06:23 2011
@@ -19,8 +19,6 @@ package org.apache.commons.lang3.text.tr
 import java.io.IOException;
 import java.io.Writer;
 
-import org.apache.commons.lang3.Range;
-
 /**
  * Translates codepoints to their XML numeric entity escaped value.
  *
@@ -29,23 +27,73 @@ import org.apache.commons.lang3.Range;
  */
 public class NumericEntityEscaper extends CodePointTranslator {
 
-    private Range<Integer> range;
+    private final int below;
+    private final int above;
+    private final boolean between;
 
     /**
      * <p>Constructs a <code>NumericEntityEscaper</code> for the specified
range. This is
-     * the underlying method for the other constructors/builders. </p>
+     * the underlying method for the other constructors/builders. The <code>below</code>
+     * and <code>above</code> boundaries are inclusive when <code>between</code>
is
+     * <code>true</code> and exclusive when it is <code>false</code>.
</p>
      *
-     * @param range range within which to escape entities
+     * @param below int value representing the lowest codepoint boundary
+     * @param above int value representing the highest codepoint boundary
+     * @param between whether to escape between the boundaries or outside them
      */
-    public NumericEntityEscaper(Range<Integer> range) {
-        this.range = range;
+    private NumericEntityEscaper(int below, int above, boolean between) {
+        this.below = below;
+        this.above = above;
+        this.between = between;
     }
 
     /**
      * <p>Constructs a <code>NumericEntityEscaper</code> for all characters.
</p>
      */
     public NumericEntityEscaper() {
-        this.range = Range.between(0, Integer.MAX_VALUE);
+        this(0, Integer.MAX_VALUE, true);
+    }
+
+    /**
+     * <p>Constructs a <code>NumericEntityEscaper</code> below the specified
value (exclusive). </p>
+     *
+     * @param codepoint below which to escape
+     * @return the newly created {@code NumericEntityEscaper} instance
+     */
+    public static NumericEntityEscaper below(int codepoint) {
+        return outsideOf(codepoint, Integer.MAX_VALUE);
+    }
+
+    /**
+     * <p>Constructs a <code>NumericEntityEscaper</code> above the specified
value (exclusive). </p>
+     *
+     * @param codepoint above which to escape
+     * @return the newly created {@code NumericEntityEscaper} instance
+     */
+    public static NumericEntityEscaper above(int codepoint) {
+        return outsideOf(0, codepoint);
+    }
+
+    /**
+     * <p>Constructs a <code>NumericEntityEscaper</code> between the specified
values (inclusive). </p>
+     *
+     * @param codepointLow above which to escape
+     * @param codepointHigh below which to escape
+     * @return the newly created {@code NumericEntityEscaper} instance
+     */
+    public static NumericEntityEscaper between(int codepointLow, int codepointHigh) {
+        return new NumericEntityEscaper(codepointLow, codepointHigh, true);
+    }
+
+    /**
+     * <p>Constructs a <code>NumericEntityEscaper</code> outside of the
specified values (exclusive). </p>
+     *
+     * @param codepointLow below which to escape
+     * @param codepointHigh above which to escape
+     * @return the newly created {@code NumericEntityEscaper} instance
+     */
+    public static NumericEntityEscaper outsideOf(int codepointLow, int codepointHigh) {
+        return new NumericEntityEscaper(codepointLow, codepointHigh, false);
     }
 
     /**
@@ -53,8 +101,14 @@ public class NumericEntityEscaper extend
      */
     @Override
     public boolean translate(int codepoint, Writer out) throws IOException {
-        if(!range.contains(codepoint)) {
-            return false;
+        if(between) {
+            if (codepoint < below || codepoint > above) {
+                return false;
+            }
+        } else {
+            if (codepoint >= below && codepoint <= above) {
+                return false;
+            }
         }
 
         out.write("&#");

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java?rev=1142151&r1=1142150&r2=1142151&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
Sat Jul  2 04:06:23 2011
@@ -19,8 +19,6 @@ package org.apache.commons.lang3.text.tr
 import java.io.IOException;
 import java.io.Writer;
 
-import org.apache.commons.lang3.Range;
-
 /**
  * Translates codepoints to their unicode escaped value.
  *
@@ -29,23 +27,73 @@ import org.apache.commons.lang3.Range;
  */
 public class UnicodeEscaper extends CodePointTranslator {
 
-    private Range<Integer> range;
+    private final int below;
+    private final int above;
+    private final boolean between;
+
+    /**
+     * <p>Constructs a <code>UnicodeEscaper</code> for all characters.
</p>
+     */
+    public UnicodeEscaper(){
+        this(0, Integer.MAX_VALUE, true);
+    }
 
     /**
      * <p>Constructs a <code>UnicodeEscaper</code> for the specified range.
This is
-     * the underlying method for the other constructors/builders. </p>
+     * the underlying method for the other constructors/builders. The <code>below</code>
+     * and <code>above</code> boundaries are inclusive when <code>between</code>
is
+     * <code>true</code> and exclusive when it is <code>false</code>.
</p>
      *
-     * @param range range within which to escape entities
+     * @param below int value representing the lowest codepoint boundary
+     * @param above int value representing the highest codepoint boundary
+     * @param between whether to escape between the boundaries or outside them
      */
-    public UnicodeEscaper(Range<Integer> range) {
-        this.range = range;
+    private UnicodeEscaper(int below, int above, boolean between) {
+        this.below = below;
+        this.above = above;
+        this.between = between;
     }
 
     /**
-     * <p>Constructs a <code>UnicodeEscaper</code> for all characters.
</p>
+     * <p>Constructs a <code>UnicodeEscaper</code> below the specified
value (exclusive). </p>
+     *
+     * @param codepoint below which to escape
+     * @return the newly created {@code UnicodeEscaper} instance
+     */
+    public static UnicodeEscaper below(int codepoint) {
+        return outsideOf(codepoint, Integer.MAX_VALUE);
+    }
+
+    /**
+     * <p>Constructs a <code>UnicodeEscaper</code> above the specified
value (exclusive). </p>
+     *
+     * @param codepoint above which to escape
+     * @return the newly created {@code UnicodeEscaper} instance
+     */
+    public static UnicodeEscaper above(int codepoint) {
+        return outsideOf(0, codepoint);
+    }
+
+    /**
+     * <p>Constructs a <code>UnicodeEscaper</code> outside of the specified
values (exclusive). </p>
+     *
+     * @param codepointLow below which to escape
+     * @param codepointHigh above which to escape
+     * @return the newly created {@code UnicodeEscaper} instance
      */
-    public UnicodeEscaper() {
-        this.range = Range.between(0, Integer.MAX_VALUE);
+    public static UnicodeEscaper outsideOf(int codepointLow, int codepointHigh) {
+        return new UnicodeEscaper(codepointLow, codepointHigh, false);
+    }
+
+    /**
+     * <p>Constructs a <code>UnicodeEscaper</code> between the specified
values (inclusive). </p>
+     *
+     * @param codepointLow above which to escape
+     * @param codepointHigh below which to escape
+     * @return the newly created {@code UnicodeEscaper} instance
+     */
+    public static UnicodeEscaper between(int codepointLow, int codepointHigh) {
+        return new UnicodeEscaper(codepointLow, codepointHigh, true);
     }
 
     /**
@@ -53,8 +101,14 @@ public class UnicodeEscaper extends Code
      */
     @Override
     public boolean translate(int codepoint, Writer out) throws IOException {
-        if(!range.contains(codepoint)) {
-            return false;
+        if(between) {
+            if (codepoint < below || codepoint > above) {
+                return false;
+            }
+        } else {
+            if (codepoint >= below && codepoint <= above) {
+                return false;
+            }
         }
 
         // TODO: Handle potential + sign per various unicode escape implementations

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java?rev=1142151&r1=1142150&r2=1142151&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
Sat Jul  2 04:06:23 2011
@@ -19,8 +19,6 @@ package org.apache.commons.lang3.text.tr
 
 import junit.framework.TestCase;
 
-import org.apache.commons.lang3.Range;
-
 /**
  * Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityEscaper}.
  * @version $Id$
@@ -28,7 +26,7 @@ import org.apache.commons.lang3.Range;
 public class NumericEntityEscaperTest extends TestCase {
 
     public void testBelow() {
-        NumericEntityEscaper nee = new NumericEntityEscaper(Range.between(0, (int)'E'));
+        NumericEntityEscaper nee = NumericEntityEscaper.below('F');
 
         String input = "ADFGZ";
         String result = nee.translate(input);
@@ -36,7 +34,7 @@ public class NumericEntityEscaperTest ex
     }
 
     public void testBetween() {
-        NumericEntityEscaper nee = new NumericEntityEscaper(Range.between((int)'F', (int)'L'));
+        NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L');
 
         String input = "ADFGZ";
         String result = nee.translate(input);
@@ -44,7 +42,7 @@ public class NumericEntityEscaperTest ex
     }
 
     public void testAbove() {
-        NumericEntityEscaper nee = new NumericEntityEscaper(Range.between((int)'G', Integer.MAX_VALUE));
+        NumericEntityEscaper nee = NumericEntityEscaper.above('F');
 
         String input = "ADFGZ";
         String result = nee.translate(input);

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java?rev=1142151&r1=1142150&r2=1142151&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
Sat Jul  2 04:06:23 2011
@@ -19,8 +19,6 @@ package org.apache.commons.lang3.text.tr
 
 import junit.framework.TestCase;
 
-import org.apache.commons.lang3.Range;
-
 /**
  * Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
  * @version $Id$
@@ -28,7 +26,7 @@ import org.apache.commons.lang3.Range;
 public class UnicodeEscaperTest extends TestCase {
 
     public void testBelow() {
-        UnicodeEscaper ue = new UnicodeEscaper(Range.between(0, (int)'E'));
+        UnicodeEscaper ue = UnicodeEscaper.below('F');
 
         String input = "ADFGZ";
         String result = ue.translate(input);
@@ -36,7 +34,7 @@ public class UnicodeEscaperTest extends 
     }
 
     public void testBetween() {
-        UnicodeEscaper ue = new UnicodeEscaper(Range.between((int)'F', (int)'L'));
+        UnicodeEscaper ue = UnicodeEscaper.between('F', 'L');
 
         String input = "ADFGZ";
         String result = ue.translate(input);
@@ -44,7 +42,7 @@ public class UnicodeEscaperTest extends 
     }
 
     public void testAbove() {
-        UnicodeEscaper ue = new UnicodeEscaper(Range.between((int)'G', Integer.MAX_VALUE));
+        UnicodeEscaper ue = UnicodeEscaper.above('F');
 
         String input = "ADFGZ";
         String result = ue.translate(input);



Mime
View raw message