Small fix in the VCF parser (now a bit quicker) and --help (--noutfa
[jvcard.git] / src / be / nikiroo / jvcard / parsers / Vcard21Parser.java
index cc7421672d62ec3b74d3f74ad92ece2f65478a1a..6d8b2babc14ca9de578ab4d4b15157e628a7ecad 100644 (file)
@@ -64,8 +64,9 @@ public class Vcard21Parser {
                                        String group = "";
 
                                        if (line.contains(":")) {
-                                               String rest = line.split(":")[0];
-                                               value = line.substring(rest.length() + 1);
+                                               int colIndex = line.indexOf(':');
+                                               String rest = line.substring(0, colIndex);
+                                               value = line.substring(colIndex + 1);
 
                                                if (rest.contains(";")) {
                                                        String tab[] = rest.split(";");
@@ -73,9 +74,11 @@ public class Vcard21Parser {
 
                                                        for (int i = 1; i < tab.length; i++) {
                                                                if (tab[i].contains("=")) {
-                                                                       String tname = tab[i].split("=")[0];
-                                                                       String tvalue = tab[i].substring(tname
-                                                                                       .length() + 1);
+                                                                       int equIndex = tab[i].indexOf('=');
+                                                                       String tname = tab[i]
+                                                                                       .substring(0, equIndex);
+                                                                       String tvalue = tab[i]
+                                                                                       .substring(equIndex + 1);
                                                                        types.add(new TypeInfo(tname, tvalue));
                                                                } else {
                                                                        types.add(new TypeInfo(tab[i], ""));
@@ -89,8 +92,9 @@ public class Vcard21Parser {
                                        }
 
                                        if (name.contains(".")) {
-                                               group = name.split("\\.")[0];
-                                               name = name.substring(group.length() + 1);
+                                               int dotIndex = name.indexOf('.');
+                                               group = name.substring(0, dotIndex);
+                                               name = name.substring(dotIndex + 1);
                                        }
 
                                        datas.add(new Data(types, name, value, group));
@@ -109,13 +113,15 @@ public class Vcard21Parser {
                builder.append("\r\n");
                builder.append("VERSION:2.1");
                builder.append("\r\n");
-               for (Data data : contact.getContent()) {
+               for (int indexData = 0; indexData < contact.size(); indexData++) {
+                       Data data = contact.get(indexData);
                        if (data.getGroup() != null && !data.getGroup().trim().equals("")) {
                                builder.append(data.getGroup().trim());
                                builder.append('.');
                        }
                        builder.append(data.getName());
-                       for (TypeInfo type : data.getTypes()) {
+                       for (int indexType = 0; indexType < data.size(); indexType++) {
+                               TypeInfo type = data.get(indexType);
                                builder.append(';');
                                builder.append(type.getName());
                                if (type.getValue() != null
@@ -139,10 +145,10 @@ public class Vcard21Parser {
        public static String toString(Card card) {
                StringBuilder builder = new StringBuilder();
 
-               for (Contact contact : card.getContactsList()) {
-                       builder.append(toString(contact, -1));
+               for (int index = 0; index < card.size(); index++) {
+                       builder.append(toString(card.get(index), -1));
                }
-               
+
                builder.append("\r\n");
 
                return builder.toString();