<commit_before>/*
 * 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 <NAME>
 */
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;
    }
    int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);    
    double latitude, longitude, altitude;
    try {
      latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
      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));
      }
    } catch (NumberFormatException nfe) {
      return null;
    }
    return new GeoParsedResult(rawText, latitude, longitude, altitude);
  }

}<commit_msg>Normalize GEO: to geo:<commit_after>/*
 * 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 <NAME>
 */
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 = queryStart < 0 ? rawText.substring(4) : rawText.substring(4, queryStart);
    int latitudeEnd = geoURIWithoutQuery.indexOf(',');
    if (latitudeEnd < 0) {
      return null;
    }
    int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);    
    double latitude, longitude, altitude;
    try {
      latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
      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));
      }
    } catch (NumberFormatException nfe) {
      return null;
    }
    return new GeoParsedResult(rawText.startsWith("GEO:") ? "geo:" + rawText.substring(4) : rawText,
                               latitude, longitude, altitude);
  }

}
{'fraction_non_alphanumeric': 0.11211043714704037, 'fraction_numerical': 0.010667224430035557, 'mean_word_length': 3.395220588235294, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4553445', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1377, 'n_words': 414}