Version 2.0.0: update sources
[jvcard.git] / src / be / nikiroo / jvcard / BaseClass.java
index 1dd76442324ca845d2f603e5dd04c532bd7bdd32..9533321b2f0b0673a5a00d236c3c8cff008a2540 100644 (file)
@@ -10,7 +10,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 
-import be.nikiroo.jvcard.resources.StringUtils;
+import be.nikiroo.utils.StringUtils;
 
 /**
  * This class is basically a List with a parent and a "dirty" state check. It
@@ -30,7 +30,7 @@ import be.nikiroo.jvcard.resources.StringUtils;
  * </p>
  * 
  * @author niki
- *
+ * 
  * @param <E>
  *            the type of the child elements
  */
@@ -275,7 +275,7 @@ public abstract class BaseClass<E extends BaseClass<?>> implements List<E> {
        public String getContentState(boolean self) {
                StringBuilder builder = new StringBuilder();
                buildContentStateRaw(builder, self);
-               return StringUtils.getHash(builder.toString());
+               return StringUtils.getMd5Hash(builder.toString());
        }
 
        /**
@@ -433,6 +433,38 @@ public abstract class BaseClass<E extends BaseClass<?>> implements List<E> {
                }
        }
 
+       /**
+        * Escape the given value to VCF standard.
+        * 
+        * @param value
+        *            the value to escape
+        * 
+        * @return the escaped value
+        */
+       protected String escape(String value) {
+               if (value == null)
+                       return null;
+
+               return value.replaceAll(",", "\\\\,").replaceAll(";", "\\\\;")
+                               .replaceAll("\n", "\\\\n");
+       }
+
+       /**
+        * Unescape the given value from the VCF standard.
+        * 
+        * @param value
+        *            the value to unescape
+        * 
+        * @return the unescaped value
+        */
+       protected String unescape(String value) {
+               if (value == null)
+                       return null;
+
+               return value.replaceAll("\\\\,", ",").replaceAll("\\\\;", ";")
+                               .replaceAll("\\\\n", "\n");
+       }
+
        /**
         * Each element that leaves the parent will pass trough here.
         *