<commit_before>// 
// Copyright 2022 The Matrix.org Foundation C.I.C
//
// 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.
//

import Foundation

/// A structure that parses a geo URI (i.e. geo:53.99803101552848,-8.25347900390625;u=10) and constructs their constituent parts.
@objcMembers
public class MXGeoURIComponents: NSObject {
    
    // MARK: - Properties
    
    public let latitude: Double
    public let longitude: Double
    public let geoURI: String
    
    // MARK: - Setup
    
    public convenience init?(geoURI: String) {
        
        guard let (latitude, longitude) = Self.parseCoordinates(from: geoURI) else {
            return nil
        }
        self.init(latitude: latitude, longitude: longitude)
    }
    
    public init(latitude: Double, longitude: Double) {
        self.latitude = latitude
        self.longitude = longitude
        self.geoURI = Self.geoURI(with: latitude, and: longitude)
        
        super.init()
    }
    
    // MARK: - Private
    
    // Parse a geo URI string like "geo:53.99803101552848,-8.25347900390625;u=10"
    private class func parseCoordinates(from geoURIString: String) -> (Double, Double)? {
        
        guard let locationString = geoURIString.components(separatedBy: ":").last?.components(separatedBy: ";").first else {
            return nil
        }
        
        let locationComponents = locationString.components(separatedBy: ",")
        
        guard locationComponents.count == 2 else {
            return nil
        }
        
        guard let latitude = Double(locationComponents[0]), let longitude = Double(locationComponents[1]) else {<commit_msg>MXGeoURIComponents: Fix geo URI parsing with altitude.<commit_after>// 
// Copyright 2022 The Matrix.org Foundation C.I.C
//
// 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.
//

import Foundation

/// A structure that parses a geo URI (i.e. geo:53.99803101552848,-8.25347900390625;u=10) and constructs their constituent parts.
@objcMembers
public class MXGeoURIComponents: NSObject {
    
    // MARK: - Properties
    
    public let latitude: Double
    public let longitude: Double
    public let geoURI: String
    
    // MARK: - Setup
    
    public convenience init?(geoURI: String) {
        
        guard let (latitude, longitude) = Self.parseCoordinates(from: geoURI) else {
            return nil
        }
        self.init(latitude: latitude, longitude: longitude)
    }
    
    public init(latitude: Double, longitude: Double) {
        self.latitude = latitude
        self.longitude = longitude
        self.geoURI = Self.geoURI(with: latitude, and: longitude)
        
        super.init()
    }
    
    // MARK: - Private
    
    // Parse a geo URI string like "geo:53.99803101552848,-8.25347900390625;u=10"
    private class func parseCoordinates(from geoURIString: String) -> (Double, Double)? {
        
        guard let locationString = geoURIString.components(separatedBy: ":").last?.components(separatedBy: ";").first else {
            return nil
        }
        
        let locationComponents = locationString.components(separatedBy: ",")
        
        guard locationComponents.count >= 2 else {
            return nil
        }
        
        guard let latitude = Double(locationComponents[0]), let longitude = Double(locationComponents[1]) else {
{'fraction_non_alphanumeric': 0.09403088269186448, 'fraction_numerical': 0.035492048859184146, 'mean_word_length': 2.5690789473684212, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 6, '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': '7585432', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1159, 'n_words': 400}