VCard format: correctly co/decode escaped values
[jvcard.git] / src / be / nikiroo / jvcard / parsers / Vcard21Parser.java
index 7d0f5e86beb98e17efb7cef1c4520fef3faa798b..5388783a48cda3bd75ddfb7d199d8ceaa92fcf89 100644 (file)
@@ -201,13 +201,13 @@ public class Vcard21Parser {
                        dataBuilder.append(type.getName());
                        if (type.getValue() != null && !type.getValue().trim().equals("")) {
                                dataBuilder.append('=');
-                               dataBuilder.append(type.getValue());
+                               dataBuilder.append(type.getRawValue());
                        }
                }
                dataBuilder.append(':');
 
                // TODO: bkey!
-               dataBuilder.append(data.getValue());
+               dataBuilder.append(data.getRawValue());
 
                // RFC says: Content lines SHOULD be folded to a maximum width of 75
                // octets -> since it is SHOULD, we will just cut it as 74/75 chars
@@ -239,6 +239,31 @@ public class Vcard21Parser {
                return lines;
        }
 
+       /**
+        * Clone the given {@link Card} by exporting then importing it again in VCF.
+        * 
+        * @param c
+        *            the {@link Card} to clone
+        * 
+        * @return the clone {@link Contact}
+        */
+       public static Card clone(Card c) {
+               return new Card(parseContact(toStrings(c)));
+       }
+
+       /**
+        * Clone the given {@link Contact} by exporting then importing it again in
+        * VCF.
+        * 
+        * @param c
+        *            the {@link Contact} to clone
+        * 
+        * @return the clone {@link Contact}
+        */
+       public static Contact clone(Contact c) {
+               return parseContact(toStrings(c, -1)).get(0);
+       }
+
        /**
         * Check if the given line is a continuation line or not.
         *