Remove some redundant 'throws'; allocate more reasonably sized StringBuffers for...
[zxing.git] / core / src / com / google / zxing / client / result / VCardResultParser.java
index 5b127f0..98488b5 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Vector;
  * Parses contact information formatted according to the VCard (2.1) format. This is not a complete
  * implementation but should parse information as commonly encoded in 2D barcodes.
  *
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
  */
 final class VCardResultParser extends ResultParser {
 
@@ -32,8 +32,11 @@ final class VCardResultParser extends ResultParser {
   }
 
   public static AddressBookParsedResult parse(Result result) {
+    // Although we should insist on the raw text ending with "END:VCARD", there's no reason
+    // to throw out everything else we parsed just because this was omitted. In fact, Eclair
+    // is doing just that, and we can't parse its contacts without this leniency.
     String rawText = result.getText();
-    if (rawText == null || !rawText.startsWith("BEGIN:VCARD") || !rawText.endsWith("END:VCARD")) {
+    if (rawText == null || !rawText.startsWith("BEGIN:VCARD")) {
       return null;
     }
     String[] names = matchVCardPrefixedField("FN", rawText, true);
@@ -61,7 +64,7 @@ final class VCardResultParser extends ResultParser {
   private static String[] matchVCardPrefixedField(String prefix, String rawText, boolean trim) {
     Vector matches = null;
     int i = 0;
-    final int max = rawText.length();
+    int max = rawText.length();
     while (i < max) {
       i = rawText.indexOf(prefix, i);
       if (i < 0) {
@@ -148,7 +151,7 @@ final class VCardResultParser extends ResultParser {
           start = end + 1;
         }
         components[componentIndex] = name.substring(start);
-        StringBuffer newName = new StringBuffer();
+        StringBuffer newName = new StringBuffer(100);
         maybeAppendComponent(components, 3, newName);
         maybeAppendComponent(components, 1, newName);
         maybeAppendComponent(components, 2, newName);