X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fparsers%2FVcard21Parser.java;h=4f9431733f122cf3f7b819e22e98fdc3c443ca9b;hb=cf77cb3542f2aefbebdb9aa00b358dbeb4489a73;hp=225915d7ca131a8a974a10ef7f1b9741d4b8cb2f;hpb=1c03abafc3987d93fa682e7b8758e51bed8a4faf;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/parsers/Vcard21Parser.java b/src/be/nikiroo/jvcard/parsers/Vcard21Parser.java index 225915d..4f94317 100644 --- a/src/be/nikiroo/jvcard/parsers/Vcard21Parser.java +++ b/src/be/nikiroo/jvcard/parsers/Vcard21Parser.java @@ -105,14 +105,24 @@ public class Vcard21Parser { return contacts; } - // -1 = no bkeys - public static String toString(Contact contact, int startingBKey) { - StringBuilder builder = new StringBuilder(); - - builder.append("BEGIN:VCARD"); - builder.append("\r\n"); - builder.append("VERSION:2.1"); - builder.append("\r\n"); + /** + * Return a {@link String} representation of the given {@link Card}, line by + * line. + * + * @param card + * the card to convert + * + * @param startingBKey + * the starting BKey number (all the other will follow) or -1 for + * no BKey + * + * @return the {@link String} representation + */ + public static List toStrings(Contact contact, int startingBKey) { + List lines = new LinkedList(); + + lines.add("BEGIN:VCARD"); + lines.add("VERSION:2.1"); for (Data data : contact) { StringBuilder dataBuilder = new StringBuilder(); if (data.getGroup() != null && !data.getGroup().trim().equals("")) { @@ -151,31 +161,38 @@ public class Vcard21Parser { } stop = Math.min(stop, dataBuilder.length()); - if (continuation) - builder.append(' '); - builder.append(dataBuilder, 0, stop); - builder.append("\r\n"); + if (continuation) { + lines.add(' ' + dataBuilder.substring(0, stop)); + } else { + lines.add(dataBuilder.substring(0, stop)); + } dataBuilder.delete(0, stop); continuation = true; } } - builder.append("END:VCARD"); - builder.append("\r\n"); + lines.add("END:VCARD"); - return builder.toString(); + return lines; } - public static String toString(Card card) { - StringBuilder builder = new StringBuilder(); + /** + * Return a {@link String} representation of the given {@link Card}, line by + * line. + * + * @param card + * the card to convert + * + * @return the {@link String} representation + */ + public static List toStrings(Card card) { + List lines = new LinkedList(); for (Contact contact : card) { - builder.append(toString(contact, -1)); + lines.addAll(toStrings(contact, -1)); } - builder.append("\r\n"); - - return builder.toString(); + return lines; } /**