コード例 #1
0
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        public override ParsedResult parse(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);
            }
            string rawText = getMassagedText(result);
            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));
        }
コード例 #2
0
        // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
        public static ProductParsedResult parse(Result result)
        {
            BarcodeFormat format = result.BarcodeFormat;

            if (!(BarcodeFormat.UPC_A.Equals(format) || BarcodeFormat.UPC_E.Equals(format) || BarcodeFormat.EAN_8.Equals(format) || BarcodeFormat.EAN_13.Equals(format)))
            {
                return(null);
            }
            // Really neither of these should happen:
            System.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

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

            return(new ProductParsedResult(rawText, normalizedProductID));
        }