2 * Copyright 2007 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 the "MECARD" address book entry format.
\r
23 /// Supported keys: N, SOUND, TEL, EMAIL, NOTE, ADR, BDAY, URL, plus ORG
\r
24 /// Unsupported keys: TEL-AV, NICKNAME
\r
26 /// Except for TEL, multiple values for keys are also not supported;
\r
27 /// the first one found takes precedence.
\r
29 /// Our understanding of the MECARD format is based on this document:
\r
31 /// http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
\r
34 /// <author> Sean Owen
\r
36 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
38 sealed class AddressBookDoCoMoResultParser:AbstractDoCoMoResultParser
\r
41 public static AddressBookParsedResult parse(Result result)
\r
43 System.String rawText = result.Text;
\r
44 if (rawText == null || !rawText.StartsWith("MECARD:"))
\r
48 System.String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
\r
49 if (rawName == null)
\r
53 System.String name = parseName(rawName[0]);
\r
54 System.String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
\r
55 System.String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
\r
56 System.String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
\r
57 System.String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
\r
58 System.String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
\r
59 System.String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
\r
60 if (birthday != null && !isStringOfDigits(birthday, 8))
\r
62 // No reason to throw out the whole card because the birthday is formatted wrong.
\r
65 System.String url = matchSingleDoCoMoPrefixedField("URL:", rawText, true);
\r
67 // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
\r
68 // honor it when found in the wild.
\r
69 System.String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);
\r
71 return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note, addresses, org, birthday, null, url);
\r
74 private static System.String parseName(System.String name)
\r
76 int comma = name.IndexOf(',');
\r
79 // Format may be last,first; switch it around
\r
80 return name.Substring(comma + 1) + ' ' + name.Substring(0, (comma) - (0));
\r