2 * Copyright 2008 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 Result = com.google.zxing.Result;
\r
18 namespace com.google.zxing.client.result
\r
21 /// <summary> Parses a "geo:" URI result, which specifies a location on the surface of
\r
22 /// the Earth as well as an optional altitude above the surface. See
\r
23 /// <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">
\r
24 /// http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00</a>.
\r
27 /// <author> Sean Owen
\r
29 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
31 sealed class GeoResultParser:ResultParser
\r
34 private GeoResultParser()
\r
38 public static GeoParsedResult parse(Result result)
\r
40 System.String rawText = result.Text;
\r
41 if (rawText == null || (!rawText.StartsWith("geo:") && !rawText.StartsWith("GEO:")))
\r
45 // Drop geo, query portion
\r
46 //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
47 int queryStart = rawText.IndexOf('?', 4);
\r
48 System.String geoURIWithoutQuery = queryStart < 0?rawText.Substring(4):rawText.Substring(4, (queryStart) - (4));
\r
49 int latitudeEnd = geoURIWithoutQuery.IndexOf(',');
\r
50 if (latitudeEnd < 0)
\r
54 //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
55 int longitudeEnd = geoURIWithoutQuery.IndexOf(',', latitudeEnd + 1);
\r
56 double latitude, longitude, altitude;
\r
59 latitude = System.Double.Parse(geoURIWithoutQuery.Substring(0, (latitudeEnd) - (0)));
\r
60 if (longitudeEnd < 0)
\r
62 longitude = System.Double.Parse(geoURIWithoutQuery.Substring(latitudeEnd + 1));
\r
67 longitude = System.Double.Parse(geoURIWithoutQuery.Substring(latitudeEnd + 1, (longitudeEnd) - (latitudeEnd + 1)));
\r
68 altitude = System.Double.Parse(geoURIWithoutQuery.Substring(longitudeEnd + 1));
\r
71 catch (System.FormatException nfe)
\r
75 return new GeoParsedResult(rawText.StartsWith("GEO:")?"geo:" + rawText.Substring(4):rawText, latitude, longitude, altitude);
\r