/*
 * Copyright 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.zxing.client.result;

import com.google.zxing.Result;

/**
 * Parses a "geo:" URI result, which specifices a location on the surface of
 * the Earth as well as an optional altitude above the surface. See
 * <a href="http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00">
 * http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00</a>.
 *
 * @author Sean Owen
 */
final class GeoResultParser extends ResultParser {

  private GeoResultParser() {
  }

  public static GeoParsedResult parse(Result result) {
    String rawText = result.getText();
    if (rawText == null || (!rawText.startsWith("geo:") && !rawText.startsWith("GEO:"))) {
      return null;
    }
    // Drop geo, query portion
    int queryStart = rawText.indexOf('?', 4);
    String geoURIWithoutQuery;
    if (queryStart < 0) {
      geoURIWithoutQuery = rawText.substring(4);
    } else {
      geoURIWithoutQuery = rawText.substring(4, queryStart);
    }
    int latitudeEnd = geoURIWithoutQuery.indexOf(',');
    if (latitudeEnd < 0) {
      return null;
    }
    double latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
    int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
    double longitude;
    double altitude; // in meters
    if (longitudeEnd < 0) {
      longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1));
      altitude = 0.0;
    } else {
      longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
      altitude = Double.parseDouble(geoURIWithoutQuery.substring(longitudeEnd + 1));
    }
    return new GeoParsedResult(rawText, latitude, longitude, altitude);
  }

}
@@ -1644,96 +1644,8 @@
   %7D%0A
-    double latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));%0A
     
@@ -1712,16 +1712,20 @@
 nd + 1);
+    
 %0A    dou
@@ -1733,52 +1733,133 @@
 le l
-ongitude;%0A    double altitude; // in meters%0A
+atitude, longitude, altitude;%0A    try %7B%0A      latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));%0A  
     
@@ -1878,24 +1878,26 @@
 eEnd %3C 0) %7B%0A
+  
       longit
@@ -1967,32 +1967,34 @@
 nd + 1));%0A      
+  
 altitude = 0.0;%0A
@@ -1993,24 +1993,26 @@
  = 0.0;%0A    
+  
 %7D else %7B%0A   
@@ -2004,24 +2004,26 @@
    %7D else %7B%0A
+  
       longit
@@ -2105,24 +2105,26 @@
 itudeEnd));%0A
+  
       altitu
@@ -2192,24 +2192,93 @@
 eEnd + 1));%0A
+      %7D%0A    %7D catch (NumberFormatException nfe) %7B%0A      return null;%0A
     %7D%0A    re

Fix Issue 143, failure on invalid geo: URIs