commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r789589 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate: EscapeUtils.java UnescapeUtils.java
Date Tue, 30 Jun 2009 07:04:07 GMT
Author: bayard
Date: Tue Jun 30 07:04:06 2009
New Revision: 789589

URL: http://svn.apache.org/viewvc?rev=789589&view=rev
Log:
Splitting out the \b \n \t \f \r Java ctrl chars as their own translator to help with the
request in LANG-498

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java?rev=789589&r1=789588&r2=789589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
Tue Jun 30 07:04:06 2009
@@ -29,12 +29,7 @@
  */
 public class EscapeUtils {
 
-    public static final CharSequenceTranslator ESCAPE_JAVA = 
-          new LookupTranslator(
-            new String[][] { 
-              {"\"", "\\\""},
-              {"\\", "\\\\"},
-          }).with(
+    public static final CharSequenceTranslator ESCAPE_JAVA_CTRL_CHARS = 
           new LookupTranslator(
             new String[][] {
               {"\b", "\\b"},
@@ -42,9 +37,18 @@
               {"\t", "\\t"},
               {"\f", "\\f"},
               {"\r", "\\r"}
+            });
+
+    public static final CharSequenceTranslator ESCAPE_JAVA = 
+          new LookupTranslator(
+            new String[][] { 
+              {"\"", "\\\""},
+              {"\\", "\\\\"},
           }).with(
-          UnicodeEscaper.outsideOf(32, 0x7f) 
-        ));
+            ESCAPE_JAVA_CTRL_CHARS
+          ).with(
+            UnicodeEscaper.outsideOf(32, 0x7f) 
+        );
 
     public static final String escapeJava(String input) {
         return ESCAPE_JAVA.translate(input);
@@ -59,14 +63,7 @@
                             {"\\", "\\\\"},
                             {"/", "\\/"}
                       }),
-            new LookupTranslator(
-                      new String[][] {
-                            {"\b", "\\b"},
-                            {"\n", "\\n"},
-                            {"\t", "\\t"},
-                            {"\f", "\\f"},
-                            {"\r", "\\r"}
-                      }),
+            ESCAPE_JAVA_CTRL_CHARS,
             UnicodeEscaper.outsideOf(32, 0x7f) 
         );
             

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java?rev=789589&r1=789588&r2=789589&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java
Tue Jun 30 07:04:06 2009
@@ -29,20 +29,26 @@
  */
 public class UnescapeUtils {
 
+    public static final CharSequenceTranslator UNESCAPE_JAVA_CTRL_CHARS = 
+            new LookupTranslator(
+                      new String[][] { 
+                            {"\\b", "\b"},
+                            {"\\n", "\n"},
+                            {"\\t", "\t"},
+                            {"\\f", "\f"},
+                            {"\\r", "\r"}
+                      });
+
     // throw "illegal character: \92" as an Exception if a \ on the end of the Java (as per
the compiler)?
     public static final CharSequenceTranslator UNESCAPE_JAVA = 
         new AggregateTranslator(
             new UnicodeUnescaper(),
+            UNESCAPE_JAVA_CTRL_CHARS,
             new LookupTranslator(
                       new String[][] { 
                             {"\\\\", "\\"},
                             {"\\\"", "\""},
                             {"\\'", "'"},
-                            {"\\r", "\r"},
-                            {"\\f", "\f"},
-                            {"\\t", "\t"},
-                            {"\\n", "\n"},
-                            {"\\b", "\b"},
                             {"\\", ""}
                       })
         );



Mime
View raw message