Fix: default FN should be trimmed
[jvcard.git] / src / be / nikiroo / jvcard / BaseClass.java
index 1dd76442324ca845d2f603e5dd04c532bd7bdd32..932337671d939885f10157769f258ba4ed73c563 100644 (file)
@@ -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.
         *