2 * Copyright 2007 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
19 import com.google.zxing.Result;
22 * Implements the "MECARD" address book entry format.
24 * Supported keys: N, TEL, EMAIL, NOTE, ADR Unsupported keys: SOUND, TEL-AV, BDAY, URL, NICKNAME
26 * Except for TEL, multiple values for keys are also not supported;
27 * the first one found takes precedence.
29 * @author srowen@google.com (Sean Owen)
31 public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
33 public static AddressBookParsedResult parse(Result result) {
34 String rawText = result.getText();
35 if (rawText == null || !rawText.startsWith("MECARD:")) {
38 String[] rawName = matchPrefixedField("N:", rawText);
39 if (rawName == null) {
42 String name = parseName(rawName[0]);
43 String[] phoneNumbers = matchPrefixedField("TEL:", rawText);
44 String email = matchSinglePrefixedField("EMAIL:", rawText);
45 String note = matchSinglePrefixedField("NOTE:", rawText);
46 String address = matchSinglePrefixedField("ADR:", rawText);
47 return new AddressBookParsedResult(new String[] {name},
57 private static String parseName(String name) {
58 int comma = name.indexOf((int) ',');
60 // Format may be last,first; switch it around
61 return name.substring(comma + 1) + ' ' + name.substring(0, comma);