Rest of cosmetic changes -- simpler, black theme with easier-to-touch buttons and...
[zxing.git] / csharp / client / result / URLTOResultParser.cs
1 /*\r
2 * Copyright 2007 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 Result = com.google.zxing.Result;\r
18 namespace com.google.zxing.client.result\r
19 {\r
20         \r
21         /// <summary> Parses the "URLTO" result format, which is of the form "URLTO:[title]:[url]".\r
22         /// This seems to be used sometimes, but I am not able to find documentation\r
23         /// on its origin or official format?\r
24         /// \r
25         /// </summary>\r
26         /// <author>  Sean Owen\r
27         /// </author>\r
28         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
29         /// </author>\r
30         sealed class URLTOResultParser\r
31         {\r
32                 \r
33                 private URLTOResultParser()\r
34                 {\r
35                 }\r
36                 \r
37                 public static URIParsedResult parse(Result result)\r
38                 {\r
39                         System.String rawText = result.Text;\r
40                         if (rawText == null || (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:")))\r
41                         {\r
42                                 return null;\r
43                         }\r
44                         //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'"\r
45                         int titleEnd = rawText.IndexOf(':', 6);\r
46                         if (titleEnd < 0)\r
47                         {\r
48                                 return null;\r
49                         }\r
50                         System.String title = titleEnd <= 6?null:rawText.Substring(6, (titleEnd) - (6));\r
51                         System.String uri = rawText.Substring(titleEnd + 1);\r
52                         return new URIParsedResult(uri, title);\r
53                 }\r
54         }\r
55 }