X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FBaseClass.java;h=932337671d939885f10157769f258ba4ed73c563;hb=99f631de95f8b89bd716b8c4011308fc1aacaeaf;hp=1dd76442324ca845d2f603e5dd04c532bd7bdd32;hpb=5ad0e17e7fea1c602cb2638a006424af9c7e33e8;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/BaseClass.java b/src/be/nikiroo/jvcard/BaseClass.java index 1dd7644..9323376 100644 --- a/src/be/nikiroo/jvcard/BaseClass.java +++ b/src/be/nikiroo/jvcard/BaseClass.java @@ -433,6 +433,38 @@ public abstract class BaseClass> implements List { } } + /** + * 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. *