// Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        override public ParsedResult parse(ZXing.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));
        }
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        public override ParsedResult parse(ZXing.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);
            }

            if (!isStringOfDigits(rawText, rawText.Length))
            {
                return(null);
            }
            // Not actually checking the checksum again here

            String normalizedProductID;

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

            return(new ProductParsedResult(rawText, normalizedProductID));
        }
Esempio n. 3
0
        public static ProductParsedResult parse(Result result)
        {
            BarcodeFormat barcodeFormat = result.BarcodeFormat;

            if (!BarcodeFormat.UPC_A.Equals(barcodeFormat) && !BarcodeFormat.UPC_E.Equals(barcodeFormat) && !BarcodeFormat.EAN_8.Equals(barcodeFormat) && !BarcodeFormat.EAN_13.Equals(barcodeFormat))
            {
                return(null);
            }
            string text = result.Text;

            if (text == null)
            {
                return(null);
            }
            int length = text.Length;

            for (int i = 0; i < length; i++)
            {
                char c = text[i];
                if (c < '0' || c > '9')
                {
                    return(null);
                }
            }
            string normalizedProductID;

            if (BarcodeFormat.UPC_E.Equals(barcodeFormat))
            {
                normalizedProductID = UPCEReader.convertUPCEtoUPCA(text);
            }
            else
            {
                normalizedProductID = text;
            }
            return(new ProductParsedResult(text, normalizedProductID));
        }