2 * Copyright 2008 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;
21 import java.util.Vector;
24 * Implements KDDI AU's address book format. See
25 * <a href="http://www.au.kddi.com/ezfactory/tec/two_dimensions/index.html">
26 * http://www.au.kddi.com/ezfactory/tec/two_dimensions/index.html</a>.
27 * (Thanks to Yuzo for translating!)
31 final class AddressBookAUResultParser extends ResultParser {
33 public static AddressBookParsedResult parse(Result result) {
34 String rawText = result.getText();
35 // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
36 if (rawText == null || rawText.indexOf("MEMORY") < 0 || rawText.indexOf("\r\n") < 0) {
40 // NAME1 and NAME2 have specific uses, namely written name and pronunciation, respectively.
41 // Therefore we treat them specially instead of as an array of names.
42 String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
43 String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);
45 String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
46 String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
47 String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
48 String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
49 return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note,
50 address, null, null, null, null);
53 private static String[] matchMultipleValuePrefix(String prefix, int max, String rawText,
56 for (int i = 1; i <= max; i++) {
57 String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', trim);
62 values = new Vector(max); // lazy init
64 values.addElement(value);
69 return toStringArray(values);