jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1174090 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ jackrabbit-spi2microkernel/src/main/java/org/a...
Date Thu, 22 Sep 2011 12:34:43 GMT
Author: mduerig
Date: Thu Sep 22 12:34:43 2011
New Revision: 1174090

URL: http://svn.apache.org/viewvc?rev=1174090&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
Merge o.a.j.u.Text and o.a.j.spi2microkernel.Text

Removed:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/
Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java?rev=1174090&r1=1174089&r2=1174090&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
Thu Sep 22 12:34:43 2011
@@ -761,6 +761,66 @@ public class Text {
         return result.toString();
     }
 
+
+
+    /**
+     * Escape all {@code target} characters of string {@code s} with the given
+     * {@code escape} character.
+     *
+     * @param s  string to escape
+     * @param target  characters to escape
+     * @param escape  escape character prepended to all target characters
+     * @return  escaped string
+     */
+    public static String escapeWith(String s, char target, char escape) {
+        if (s == null) {
+            return null;
+        }
+
+        StringBuilder sb = new StringBuilder();
+        for (int k = 0; k < s.length(); k++) {
+            char c = s.charAt(k);
+            if (c == target || c == escape) {
+                sb.append(escape);
+            }
+            sb.append(c);
+        }
+
+        return sb.toString();
+    }
+
+    /**
+     * Unescape all characters in string {@code s} which are escaped with the
+     * given {@code escape} character.
+     *
+     * @param s  string to unescape
+     * @param escape  escape character prepended to all target characters
+     * @return  unescaped string
+     */
+    public static String unescapeWith(String s, char escape) {
+        if (s == null) {
+            return null;
+        }
+
+        boolean escaping = false;
+        StringBuilder sb = new StringBuilder();
+        for (int k = 0; k < s.length(); k++) {
+            char c = s.charAt(k);
+            if (escaping) {
+                sb.append(c);
+                escaping = false;
+            }
+            else if (c == escape) {
+                escaping = true;
+            }
+            else {
+                sb.append(c);
+            }
+        }
+
+        return sb.toString();
+    }
+
     private static byte decodeDigit(byte b) {
         if (b >= 0x30 && b <= 0x39) {
             return (byte) (b - 0x30);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java?rev=1174090&r1=1174089&r2=1174090&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitMessage.java
Thu Sep 22 12:34:43 2011
@@ -2,7 +2,7 @@ package org.apache.jackrabbit.spi2microk
 
 
 import org.apache.jackrabbit.spi.commons.util.Unchecked;
-import org.apache.jackrabbit.spi2microkernel.util.Text;
+import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -82,11 +82,11 @@ public class CommitMessage {
     }
 
     private static String escape(String s) {
-        return Text.escape(s, SEPARATOR_CHAR, ESCAPE_CHAR);
+        return Text.escapeWith(s, SEPARATOR_CHAR, ESCAPE_CHAR);
     }
 
     private static String unescape(String s) {
-        return Text.unescape(s, ESCAPE_CHAR);
+        return Text.unescapeWith(s, ESCAPE_CHAR);
     }
         
 }



Mime
View raw message