2 * Copyright 2008 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using Result = com.google.zxing.Result;
\r
18 namespace com.google.zxing.client.result
\r
21 /// <summary> Implements KDDI AU's address book format. See
\r
22 /// <a href="http://www.au.kddi.com/ezfactory/tec/two_dimensions/index.html">
\r
23 /// http://www.au.kddi.com/ezfactory/tec/two_dimensions/index.html</a>.
\r
24 /// (Thanks to Yuzo for translating!)
\r
27 /// <author> Sean Owen
\r
29 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
31 sealed class AddressBookAUResultParser:ResultParser
\r
34 public static AddressBookParsedResult parse(Result result)
\r
36 System.String rawText = result.Text;
\r
37 // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
\r
38 if (rawText == null || rawText.IndexOf("MEMORY") < 0 || rawText.IndexOf("\r\n") < 0)
\r
43 // NAME1 and NAME2 have specific uses, namely written name and pronunciation, respectively.
\r
44 // Therefore we treat them specially instead of as an array of names.
\r
45 System.String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
\r
46 System.String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);
\r
48 System.String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
\r
49 System.String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
\r
50 System.String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
\r
51 System.String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
\r
52 System.String[] addresses = address == null?null:new System.String[]{address};
\r
53 return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note, addresses, null, null, null, null);
\r
56 private static System.String[] matchMultipleValuePrefix(System.String prefix, int max, System.String rawText, bool trim)
\r
58 System.Collections.ArrayList values = null;
\r
59 for (int i = 1; i <= max; i++)
\r
61 System.String value_Renamed = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', trim);
\r
62 if (value_Renamed == null)
\r
68 values = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(max)); // lazy init
\r
70 values.Add(value_Renamed);
\r
76 return toStringArray(values);
\r