commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1090111 - 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 Fri, 08 Apr 2011 04:47:22 GMT
Author: bayard
Date: Fri Apr  8 04:47:21 2011
New Revision: 1090111

URL: http://svn.apache.org/viewvc?rev=1090111&view=rev
Log:
Moving text translation classes to the Range class for its configuration

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=1090111&r1=1090110&r2=1090111&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
Fri Apr  8 04:47:21 2011
@@ -57,7 +57,10 @@ public class StringEscapeUtils {
           }).with(
             new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE())
           ).with(
-            UnicodeEscaper.outsideOf(32, 0x7f) 
+            new AggregateTranslator(
+                new UnicodeEscaper(Range.between(0, 31)), 
+                new UnicodeEscaper(Range.between(0x80, Integer.MAX_VALUE)) 
+            )
         );
 
     /**
@@ -79,7 +82,10 @@ public class StringEscapeUtils {
                             {"/", "\\/"}
                       }),
             new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE()),
-            UnicodeEscaper.outsideOf(32, 0x7f) 
+            new AggregateTranslator(
+                new UnicodeEscaper(Range.between(0, 31)), 
+                new UnicodeEscaper(Range.between(0x80, Integer.MAX_VALUE)) 
+            )
         );
             
     /**

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=1090111&r1=1090110&r2=1090111&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
Fri Apr  8 04:47:21 2011
@@ -19,6 +19,8 @@ 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.
  *
@@ -27,73 +29,23 @@ import java.io.Writer;
  */
 public class NumericEntityEscaper extends CodePointTranslator {
 
-    private final int below;
-    private final int above;
-    private final boolean between;
+    private Range<Integer> range;
 
     /**
      * <p>Constructs a <code>NumericEntityEscaper</code> for the specified
range. This is
-     * 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>
+     * the underlying method for the other constructors/builders. </p>
      *
-     * @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
+     * @param range range within which to escape entities
      */
-    private NumericEntityEscaper(int below, int above, boolean between) {
-        this.below = below;
-        this.above = above;
-        this.between = between;
+    public NumericEntityEscaper(Range<Integer> range) {
+        this.range = range;
     }
 
     /**
      * <p>Constructs a <code>NumericEntityEscaper</code> for all characters.
</p>
      */
     public NumericEntityEscaper() {
-        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);
+        this.range = Range.between(0, Integer.MAX_VALUE);
     }
 
     /**
@@ -101,14 +53,8 @@ public class NumericEntityEscaper extend
      */
     @Override
     public boolean translate(int codepoint, Writer out) throws IOException {
-        if(between) {
-            if (codepoint < below || codepoint > above) {
-                return false;
-            }
-        } else {
-            if (codepoint >= below && codepoint <= above) {
-                return false;
-            }
+        if(!range.contains(codepoint)) {
+            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=1090111&r1=1090110&r2=1090111&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
Fri Apr  8 04:47:21 2011
@@ -19,6 +19,8 @@ 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.
  *
@@ -27,73 +29,23 @@ import java.io.Writer;
  */
 public class UnicodeEscaper extends CodePointTranslator {
 
-    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);
-    }
+    private Range<Integer> range;
 
     /**
      * <p>Constructs a <code>UnicodeEscaper</code> for the specified range.
This is
-     * 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 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
-     */
-    private UnicodeEscaper(int below, int above, boolean between) {
-        this.below = below;
-        this.above = above;
-        this.between = between;
-    }
-
-    /**
-     * <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>
+     * the underlying method for the other constructors/builders. </p>
      *
-     * @param codepointLow below which to escape
-     * @param codepointHigh above which to escape
-     * @return the newly created {@code UnicodeEscaper} instance
+     * @param range range within which to escape entities
      */
-    public static UnicodeEscaper outsideOf(int codepointLow, int codepointHigh) {
-        return new UnicodeEscaper(codepointLow, codepointHigh, false);
+    public UnicodeEscaper(Range<Integer> range) {
+        this.range = range;
     }
 
     /**
-     * <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
+     * <p>Constructs a <code>UnicodeEscaper</code> for all characters.
</p>
      */
-    public static UnicodeEscaper between(int codepointLow, int codepointHigh) {
-        return new UnicodeEscaper(codepointLow, codepointHigh, true);
+    public UnicodeEscaper() {
+        this.range = Range.between(0, Integer.MAX_VALUE);
     }
 
     /**
@@ -101,14 +53,8 @@ public class UnicodeEscaper extends Code
      */
     @Override
     public boolean translate(int codepoint, Writer out) throws IOException {
-        if(between) {
-            if (codepoint < below || codepoint > above) {
-                return false;
-            }
-        } else {
-            if (codepoint >= below && codepoint <= above) {
-                return false;
-            }
+        if(!range.contains(codepoint)) {
+            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=1090111&r1=1090110&r2=1090111&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
Fri Apr  8 04:47:21 2011
@@ -19,6 +19,8 @@ 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$
@@ -26,7 +28,7 @@ import junit.framework.TestCase;
 public class NumericEntityEscaperTest extends TestCase {
 
     public void testBelow() {
-        NumericEntityEscaper nee = NumericEntityEscaper.below('F');
+        NumericEntityEscaper nee = new NumericEntityEscaper(Range.between(0, (int)'E'));
 
         String input = "ADFGZ";
         String result = nee.translate(input);
@@ -34,7 +36,7 @@ public class NumericEntityEscaperTest ex
     }
 
     public void testBetween() {
-        NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L');
+        NumericEntityEscaper nee = new NumericEntityEscaper(Range.between((int)'F', (int)'L'));
 
         String input = "ADFGZ";
         String result = nee.translate(input);
@@ -42,7 +44,7 @@ public class NumericEntityEscaperTest ex
     }
 
     public void testAbove() {
-        NumericEntityEscaper nee = NumericEntityEscaper.above('F');
+        NumericEntityEscaper nee = new NumericEntityEscaper(Range.between((int)'G', Integer.MAX_VALUE));
 
         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=1090111&r1=1090110&r2=1090111&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
Fri Apr  8 04:47:21 2011
@@ -19,6 +19,8 @@ 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$
@@ -26,7 +28,7 @@ import junit.framework.TestCase;
 public class UnicodeEscaperTest extends TestCase {
 
     public void testBelow() {
-        UnicodeEscaper ue = UnicodeEscaper.below('F');
+        UnicodeEscaper ue = new UnicodeEscaper(Range.between(0, (int)'E'));
 
         String input = "ADFGZ";
         String result = ue.translate(input);
@@ -34,7 +36,7 @@ public class UnicodeEscaperTest extends 
     }
 
     public void testBetween() {
-        UnicodeEscaper ue = UnicodeEscaper.between('F', 'L');
+        UnicodeEscaper ue = new UnicodeEscaper(Range.between((int)'F', (int)'L'));
 
         String input = "ADFGZ";
         String result = ue.translate(input);
@@ -42,7 +44,7 @@ public class UnicodeEscaperTest extends 
     }
 
     public void testAbove() {
-        UnicodeEscaper ue = UnicodeEscaper.above('F');
+        UnicodeEscaper ue = new UnicodeEscaper(Range.between((int)'G', Integer.MAX_VALUE));
 
         String input = "ADFGZ";
         String result = ue.translate(input);



Mime
View raw message