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 BarcodeFormat = com.google.zxing.BarcodeFormat;
\r
18 using Result = com.google.zxing.Result;
\r
19 using UPCEReader = com.google.zxing.oned.UPCEReader;
\r
20 namespace com.google.zxing.client.result
\r
23 /// <summary> Parses strings of digits that represent a UPC code.
\r
26 /// <author> dswitkin@google.com (Daniel Switkin)
\r
28 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
30 sealed class ProductResultParser:ResultParser
\r
33 private ProductResultParser()
\r
37 // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
\r
38 public static ProductParsedResult parse(Result result)
\r
40 BarcodeFormat format = result.BarcodeFormat;
\r
41 if (!(BarcodeFormat.UPC_A.Equals(format) || BarcodeFormat.UPC_E.Equals(format) || BarcodeFormat.EAN_8.Equals(format) || BarcodeFormat.EAN_13.Equals(format)))
\r
45 // Really neither of these should happen:
\r
46 System.String rawText = result.Text;
\r
47 if (rawText == null)
\r
52 int length = rawText.Length;
\r
53 for (int x = 0; x < length; x++)
\r
55 char c = rawText[x];
\r
56 if (c < '0' || c > '9')
\r
61 // Not actually checking the checksum again here
\r
63 System.String normalizedProductID;
\r
64 // Expand UPC-E for purposes of searching
\r
65 if (BarcodeFormat.UPC_E.Equals(format))
\r
67 normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
\r
71 normalizedProductID = rawText;
\r
74 return new ProductParsedResult(rawText, normalizedProductID);
\r