Small fixes for 1.6 release
[zxing.git] / csharp / client / result / ISBNResultParser.cs
1 /*\r
2 * Copyright 2008 ZXing authors\r
3 *\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
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\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
15 */\r
16 using System;\r
17 using BarcodeFormat = com.google.zxing.BarcodeFormat;\r
18 using Result = com.google.zxing.Result;\r
19 namespace com.google.zxing.client.result\r
20 {\r
21         \r
22         /// <summary> Parses strings of digits that represent a ISBN.\r
23         /// \r
24         /// </summary>\r
25         /// <author>  jbreiden@google.com (Jeff Breidenbach)\r
26         /// </author>\r
27         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
28         /// </author>\r
29         public class ISBNResultParser:ResultParser\r
30         {\r
31                 \r
32                 private ISBNResultParser()\r
33                 {\r
34                 }\r
35                 \r
36                 // ISBN-13 For Dummies \r
37                 // http://www.bisg.org/isbn-13/for.dummies.html\r
38                 public static ISBNParsedResult parse(Result result)\r
39                 {\r
40                         BarcodeFormat format = result.BarcodeFormat;\r
41                         if (!BarcodeFormat.EAN_13.Equals(format))\r
42                         {\r
43                                 return null;\r
44                         }\r
45                         System.String rawText = result.Text;\r
46                         if (rawText == null)\r
47                         {\r
48                                 return null;\r
49                         }\r
50                         int length = rawText.Length;\r
51                         if (length != 13)\r
52                         {\r
53                                 return null;\r
54                         }\r
55                         if (!rawText.StartsWith("978") && !rawText.StartsWith("979"))\r
56                         {\r
57                                 return null;\r
58                         }\r
59                         \r
60                         return new ISBNParsedResult(rawText);\r
61                 }\r
62         }\r
63 }