Пример #1
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (!(rawText.StartsWith("smtp:") || rawText.StartsWith("SMTP:")))
            {
                return(null);
            }
            String emailAddress = rawText.Substring(5);
            String subject      = null;
            String body         = null;
            int    colon        = emailAddress.IndexOf(':');

            if (colon >= 0)
            {
                subject      = emailAddress.Substring(colon + 1);
                emailAddress = emailAddress.Substring(0, colon);
                colon        = subject.IndexOf(':');
                if (colon >= 0)
                {
                    body    = subject.Substring(colon + 1);
                    subject = subject.Substring(0, colon);
                }
            }
            String mailtoURI = "mailto:" + emailAddress;

            return(new EmailAddressParsedResult(emailAddress, subject, body, mailtoURI));
        }
Пример #2
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            var rawText = result.Text;

            if (!rawText.StartsWith("WIFI:"))
            {
                return(null);
            }
            var ssid = matchSinglePrefixedField("S:", rawText, ';', false);

            if (string.IsNullOrEmpty(ssid))
            {
                return(null);
            }
            var pass = matchSinglePrefixedField("P:", rawText, ';', false);
            var type = matchSinglePrefixedField("T:", rawText, ';', false) ?? "nopass";

            bool hidden = false;

#if WindowsCE
            try { hidden = Boolean.Parse(matchSinglePrefixedField("H:", rawText, ';', false)); } catch { }
#else
            Boolean.TryParse(matchSinglePrefixedField("H:", rawText, ';', false), out hidden);
#endif

            return(new WifiParsedResult(type, ssid, pass, hidden));
        }
Пример #3
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null ||
                !(rawText.StartsWith("sms:") || rawText.StartsWith("SMS:") ||
                  rawText.StartsWith("mms:") || rawText.StartsWith("MMS:")))
            {
                return(null);
            }

            // Check up front if this is a URI syntax string with query arguments
            var    nameValuePairs = parseNameValuePairs(rawText);
            String subject        = null;
            String body           = null;
            var    querySyntax    = false;

            if (nameValuePairs != null && nameValuePairs.Count != 0)
            {
                subject     = nameValuePairs["subject"];
                body        = nameValuePairs["body"];
                querySyntax = true;
            }

            // Drop sms, query portion
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            var    queryStart = rawText.IndexOf('?', 4);
            String smsURIWithoutQuery;

            // If it's not query syntax, the question mark is part of the subject or message
            if (queryStart < 0 || !querySyntax)
            {
                smsURIWithoutQuery = rawText.Substring(4);
            }
            else
            {
                smsURIWithoutQuery = rawText.Substring(4, (queryStart) - (4));
            }

            int lastComma = -1;
            int comma;
            var numbers = new List <String>(1);
            var vias    = new List <String>(1);

            while ((comma = smsURIWithoutQuery.IndexOf(',', lastComma + 1)) > lastComma)
            {
                String numberPart = smsURIWithoutQuery.Substring(lastComma + 1, comma);
                addNumberVia(numbers, vias, numberPart);
                lastComma = comma;
            }
            addNumberVia(numbers, vias, smsURIWithoutQuery.Substring(lastComma + 1));

            return(new SMSParsedResult(SupportClass.toStringArray(numbers),
                                       SupportClass.toStringArray(vias),
                                       subject,
                                       body));
        }
Пример #4
0
 public static ParsedResult parseResult(z.Barcode.Result theResult)
 {
     foreach (var parser in PARSERS)
     {
         var result = parser.parse(theResult);
         if (result != null)
         {
             return(result);
         }
     }
     return(new TextParsedResult(theResult.Text, null));
 }
Пример #5
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null || !rawText.StartsWith("MECARD:"))
            {
                return(null);
            }
            String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
            if (rawName == null)
            {
                return(null);
            }
            String name          = parseName(rawName[0]);
            String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);

            String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
            String[] emails       = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
            String   note         = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);

            String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
            String   birthday  = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);

            if (birthday != null && !isStringOfDigits(birthday, 8))
            {
                // No reason to throw out the whole card because the birthday is formatted wrong.
                birthday = null;
            }
            String[] urls = matchDoCoMoPrefixedField("URL:", rawText, true);

            // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
            // honor it when found in the wild.
            String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);

            return(new AddressBookParsedResult(maybeWrap(name),
                                               null,
                                               pronunciation,
                                               phoneNumbers,
                                               null,
                                               emails,
                                               null,
                                               null,
                                               note,
                                               addresses,
                                               null,
                                               org,
                                               birthday,
                                               null,
                                               urls,
                                               null));
        }
Пример #6
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null ||
                (!rawText.StartsWith("tel:") && !rawText.StartsWith("TEL:")))
            {
                return(null);
            }
            // Normalize "TEL:" to "tel:"
            String telURI = rawText.StartsWith("TEL:") ? "tel:" + rawText.Substring(4) : rawText;
            // Drop tel, query portion
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            int    queryStart = rawText.IndexOf('?', 4);
            String number     = queryStart < 0 ? rawText.Substring(4) : rawText.Substring(4, (queryStart) - (4));

            return(new TelParsedResult(number, telURI, null));
        }
Пример #7
0
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        override public ParsedResult parse(z.Barcode.Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E ||
                  format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13))
            {
                return(null);
            }
            // Really neither of these should happen:
            String rawText = result.Text;

            if (rawText == null)
            {
                return(null);
            }

            int length = rawText.Length;

            for (int x = 0; x < length; x++)
            {
                char c = rawText[x];
                if (c < '0' || c > '9')
                {
                    return(null);
                }
            }
            // Not actually checking the checksum again here

            String normalizedProductID;

            // Expand UPC-E for purposes of searching
            if (format == BarcodeFormat.UPC_E)
            {
                normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
            }
            else
            {
                normalizedProductID = rawText;
            }

            return(new ProductParsedResult(rawText, normalizedProductID));
        }
Пример #8
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null)
            {
                return(null);
            }
            String emailAddress;

            if (rawText.ToLower().StartsWith("mailto:"))
            {
                // If it starts with mailto:, assume it is definitely trying to be an email address
                emailAddress = rawText.Substring(7);
                int queryStart = emailAddress.IndexOf('?');
                if (queryStart >= 0)
                {
                    emailAddress = emailAddress.Substring(0, queryStart);
                }
                emailAddress = urlDecode(emailAddress);
                var    nameValues = parseNameValuePairs(rawText);
                String subject    = null;
                String body       = null;
                if (nameValues != null)
                {
                    if (emailAddress.Length == 0)
                    {
                        emailAddress = nameValues["to"];
                    }
                    subject = nameValues["subject"];
                    body    = nameValues["body"];
                }
                return(new EmailAddressParsedResult(emailAddress, subject, body, rawText));
            }

            if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText))
            {
                return(null);
            }
            emailAddress = rawText;
            return(new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress));
        }
Пример #9
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            var rawText = result.Text;

            if (rawText == null ||
                (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:")))
            {
                return(null);
            }
            //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
            int titleEnd = rawText.IndexOf(':', 6);

            if (titleEnd < 0)
            {
                return(null);
            }
            var title = titleEnd <= 6 ? null : rawText.Substring(6, (titleEnd) - (6));
            var uri   = rawText.Substring(titleEnd + 1);

            return(new URIParsedResult(uri, title));
        }
Пример #10
0
        /// <summary>
        /// See <a href="http://www.bisg.org/isbn-13/for.dummies.html">ISBN-13 For Dummies</a>
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        override public ParsedResult parse(z.Barcode.Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (format != BarcodeFormat.EAN_13)
            {
                return(null);
            }
            String rawText = result.Text;
            int    length  = rawText.Length;

            if (length != 13)
            {
                return(null);
            }
            if (!rawText.StartsWith("978") && !rawText.StartsWith("979"))
            {
                return(null);
            }

            return(new ISBNParsedResult(rawText));
        }
Пример #11
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (!(rawText.StartsWith("smsto:") || rawText.StartsWith("SMSTO:") ||
                  rawText.StartsWith("mmsto:") || rawText.StartsWith("MMSTO:")))
            {
                return(null);
            }
            // Thanks to dominik.wild for suggesting this enhancement to support
            // smsto:number:body URIs
            String number    = rawText.Substring(6);
            String body      = null;
            int    bodyStart = number.IndexOf(':');

            if (bodyStart >= 0)
            {
                body   = number.Substring(bodyStart + 1);
                number = number.Substring(0, bodyStart);
            }
            return(new SMSParsedResult(number, null, null, body));
        }
        override public ParsedResult parse(z.Barcode.Result result)
        {
            var rawText = result.Text;

            // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
            if (rawText == null || rawText.IndexOf("MEMORY") < 0 || rawText.IndexOf("\r\n") < 0)
            {
                return(null);
            }

            // NAME1 and NAME2 have specific uses, namely written name and pronunciation, respectively.
            // Therefore we treat them specially instead of as an array of names.
            var name          = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
            var pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);

            var phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
            var emails       = matchMultipleValuePrefix("MAIL", 3, rawText, true);
            var note         = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
            var address      = matchSinglePrefixedField("ADD:", rawText, '\r', true);
            var addresses    = address == null ? null : new [] { address };

            return(new AddressBookParsedResult(maybeWrap(name),
                                               null,
                                               pronunciation,
                                               phoneNumbers,
                                               null,
                                               emails,
                                               null,
                                               null,
                                               note,
                                               addresses,
                                               null,
                                               null,
                                               null,
                                               null,
                                               null,
                                               null));
        }
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null || !rawText.StartsWith("MEBKM:"))
            {
                return(null);
            }
            String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);

            String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
            if (rawUri == null)
            {
                return(null);
            }
            String uri = rawUri[0];

            if (!URIResultParser.isBasicallyValidURI(uri))
            {
                return(null);
            }
            return(new URIParsedResult(uri, title));
        }
Пример #14
0
        // Yes, we extend AbstractDoCoMoResultParser since the format is very much
        // like the DoCoMo MECARD format, but this is not technically one of
        // DoCoMo's proposed formats

        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null || !rawText.StartsWith("BIZCARD:"))
            {
                return(null);
            }
            String firstName = matchSingleDoCoMoPrefixedField("N:", rawText, true);
            String lastName  = matchSingleDoCoMoPrefixedField("X:", rawText, true);
            String fullName  = buildName(firstName, lastName);
            String title     = matchSingleDoCoMoPrefixedField("T:", rawText, true);
            String org       = matchSingleDoCoMoPrefixedField("C:", rawText, true);

            String[] addresses    = matchDoCoMoPrefixedField("A:", rawText, true);
            String   phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
            String   phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
            String   phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
            String   email        = matchSingleDoCoMoPrefixedField("E:", rawText, true);

            return(new AddressBookParsedResult(maybeWrap(fullName),
                                               null,
                                               null,
                                               buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3),
                                               null,
                                               maybeWrap(email),
                                               null,
                                               null,
                                               null,
                                               addresses,
                                               null,
                                               org,
                                               null,
                                               title,
                                               null,
                                               null));
        }
Пример #15
0
        override public ParsedResult parse(z.Barcode.Result result)
        {
            String rawText = result.Text;

            if (rawText == null)
            {
                return(null);
            }
            int vEventStart = rawText.IndexOf("BEGIN:VEVENT");

            if (vEventStart < 0)
            {
                return(null);
            }

            String summary = matchSingleVCardPrefixedField("SUMMARY", rawText, true);
            String start   = matchSingleVCardPrefixedField("DTSTART", rawText, true);

            if (start == null)
            {
                return(null);
            }
            String end       = matchSingleVCardPrefixedField("DTEND", rawText, true);
            String duration  = matchSingleVCardPrefixedField("DURATION", rawText, true);
            String location  = matchSingleVCardPrefixedField("LOCATION", rawText, true);
            String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText, true));

            String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText, true);
            if (attendees != null)
            {
                for (int i = 0; i < attendees.Length; i++)
                {
                    attendees[i] = stripMailto(attendees[i]);
                }
            }
            String description = matchSingleVCardPrefixedField("DESCRIPTION", rawText, true);

            String geoString = matchSingleVCardPrefixedField("GEO", rawText, true);
            double latitude;
            double longitude;

            if (geoString == null)
            {
                latitude  = Double.NaN;
                longitude = Double.NaN;
            }
            else
            {
                int semicolon = geoString.IndexOf(';');
#if WindowsCE
                try { latitude = Double.Parse(geoString.Substring(0, semicolon), NumberStyles.Float, CultureInfo.InvariantCulture); }
                catch { return(null); }
                try { longitude = Double.Parse(geoString.Substring(semicolon + 1), NumberStyles.Float, CultureInfo.InvariantCulture); }
                catch { return(null); }
#else
                if (!Double.TryParse(geoString.Substring(0, semicolon), NumberStyles.Float, CultureInfo.InvariantCulture, out latitude))
                {
                    return(null);
                }
                if (!Double.TryParse(geoString.Substring(semicolon + 1), NumberStyles.Float, CultureInfo.InvariantCulture, out longitude))
                {
                    return(null);
                }
#endif
            }

            try
            {
                return(new CalendarParsedResult(summary,
                                                start,
                                                end,
                                                duration,
                                                location,
                                                organizer,
                                                attendees,
                                                description,
                                                latitude,
                                                longitude));
            }
            catch (ArgumentException)
            {
                return(null);
            }
        }
Пример #16
0
        override public ParsedResult parse(z.Barcode.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.Text;
            var    m       = BEGIN_VCARD.Match(rawText);

            if (!m.Success || m.Index != 0)
            {
                return(null);
            }
            List <List <String> > names = matchVCardPrefixedField("FN", rawText, true, false);

            if (names == null)
            {
                // If no display names found, look for regular name fields and format them
                names = matchVCardPrefixedField("N", rawText, true, false);
                formatNames(names);
            }
            List <String> nicknameString = matchSingleVCardPrefixedField("NICKNAME", rawText, true, false);

            String[] nicknames = nicknameString == null ? null : COMMA.Split(nicknameString[0]);
            List <List <String> > phoneNumbers = matchVCardPrefixedField("TEL", rawText, true, false);
            List <List <String> > emails       = matchVCardPrefixedField("EMAIL", rawText, true, false);
            List <String>         note         = matchSingleVCardPrefixedField("NOTE", rawText, false, false);
            List <List <String> > addresses    = matchVCardPrefixedField("ADR", rawText, true, true);
            List <String>         org          = matchSingleVCardPrefixedField("ORG", rawText, true, true);
            List <String>         birthday     = matchSingleVCardPrefixedField("BDAY", rawText, true, false);

            if (birthday != null && !isLikeVCardDate(birthday[0]))
            {
                birthday = null;
            }
            List <String>         title            = matchSingleVCardPrefixedField("TITLE", rawText, true, false);
            List <List <String> > urls             = matchVCardPrefixedField("URL", rawText, true, false);
            List <String>         instantMessenger = matchSingleVCardPrefixedField("IMPP", rawText, true, false);
            List <String>         geoString        = matchSingleVCardPrefixedField("GEO", rawText, true, false);

            String[] geo = geoString == null ? null : SEMICOLON_OR_COMMA.Split(geoString[0]);
            if (geo != null && geo.Length != 2)
            {
                geo = null;
            }
            return(new AddressBookParsedResult(toPrimaryValues(names),
                                               nicknames,
                                               null,
                                               toPrimaryValues(phoneNumbers),
                                               toTypes(phoneNumbers),
                                               toPrimaryValues(emails),
                                               toTypes(emails),
                                               toPrimaryValue(instantMessenger),
                                               toPrimaryValue(note),
                                               toPrimaryValues(addresses),
                                               toTypes(addresses),
                                               toPrimaryValue(org),
                                               toPrimaryValue(birthday),
                                               toPrimaryValue(title),
                                               toPrimaryValues(urls),
                                               geo));
        }
        override public ParsedResult parse(z.Barcode.Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (format != BarcodeFormat.RSS_EXPANDED)
            {
                // ExtendedProductParsedResult NOT created. Not a RSS Expanded barcode
                return(null);
            }
            // Really neither of these should happen:
            String rawText = result.Text;

            if (rawText == null)
            {
                // ExtendedProductParsedResult NOT created. Input text is NULL
                return(null);
            }

            String productID       = null;
            String sscc            = null;
            String lotNumber       = null;
            String productionDate  = null;
            String packagingDate   = null;
            String bestBeforeDate  = null;
            String expirationDate  = null;
            String weight          = null;
            String weightType      = null;
            String weightIncrement = null;
            String price           = null;
            String priceIncrement  = null;
            String priceCurrency   = null;
            var    uncommonAIs     = new Dictionary <String, String>();

            int i = 0;

            while (i < rawText.Length)
            {
                String ai = findAIvalue(i, rawText);
                if (ai == null)
                {
                    // Error. Code doesn't match with RSS expanded pattern
                    // ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
                    return(null);
                }
                i += ai.Length + 2;
                String value = findValue(i, rawText);
                i += value.Length;

                if ("00".Equals(ai))
                {
                    sscc = value;
                }
                else if ("01".Equals(ai))
                {
                    productID = value;
                }
                else if ("10".Equals(ai))
                {
                    lotNumber = value;
                }
                else if ("11".Equals(ai))
                {
                    productionDate = value;
                }
                else if ("13".Equals(ai))
                {
                    packagingDate = value;
                }
                else if ("15".Equals(ai))
                {
                    bestBeforeDate = value;
                }
                else if ("17".Equals(ai))
                {
                    expirationDate = value;
                }
                else if ("3100".Equals(ai) || "3101".Equals(ai) ||
                         "3102".Equals(ai) || "3103".Equals(ai) ||
                         "3104".Equals(ai) || "3105".Equals(ai) ||
                         "3106".Equals(ai) || "3107".Equals(ai) ||
                         "3108".Equals(ai) || "3109".Equals(ai))
                {
                    weight          = value;
                    weightType      = ExpandedProductParsedResult.KILOGRAM;
                    weightIncrement = ai.Substring(3);
                }
                else if ("3200".Equals(ai) || "3201".Equals(ai) ||
                         "3202".Equals(ai) || "3203".Equals(ai) ||
                         "3204".Equals(ai) || "3205".Equals(ai) ||
                         "3206".Equals(ai) || "3207".Equals(ai) ||
                         "3208".Equals(ai) || "3209".Equals(ai))
                {
                    weight          = value;
                    weightType      = ExpandedProductParsedResult.POUND;
                    weightIncrement = ai.Substring(3);
                }
                else if ("3920".Equals(ai) || "3921".Equals(ai) ||
                         "3922".Equals(ai) || "3923".Equals(ai))
                {
                    price          = value;
                    priceIncrement = ai.Substring(3);
                }
                else if ("3930".Equals(ai) || "3931".Equals(ai) ||
                         "3932".Equals(ai) || "3933".Equals(ai))
                {
                    if (value.Length < 4)
                    {
                        // The value must have more of 3 symbols (3 for currency and
                        // 1 at least for the price)
                        // ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
                        return(null);
                    }
                    price          = value.Substring(3);
                    priceCurrency  = value.Substring(0, 3);
                    priceIncrement = ai.Substring(3);
                }
                else
                {
                    // No match with common AIs
                    uncommonAIs[ai] = value;
                }
            }

            return(new ExpandedProductParsedResult(rawText,
                                                   productID,
                                                   sscc,
                                                   lotNumber,
                                                   productionDate,
                                                   packagingDate,
                                                   bestBeforeDate,
                                                   expirationDate,
                                                   weight,
                                                   weightType,
                                                   weightIncrement,
                                                   price,
                                                   priceIncrement,
                                                   priceCurrency,
                                                   uncommonAIs));
        }
Пример #18
0
 /// <summary>
 /// Attempts to parse the raw {@link Result}'s contents as a particular type
 /// of information (email, URL, etc.) and return a {@link ParsedResult} encapsulating
 /// the result of parsing.
 /// </summary>
 /// <param name="theResult">The result.</param>
 /// <returns></returns>
 public abstract ParsedResult parse(z.Barcode.Result theResult);