<commit_before>//
//  CLLocation.swift
//  ZamzamKit
//
//  Created by <NAME> on 2/17/16.
//  Copyright © 2016 Zamzam. All rights reserved.
//
import Foundation
import CoreLocation

public extension CLLocation {
    
    /**
     Retrieves location name for a place
     
     - parameter coordinates: Latitude and longitude] coordinates
     - parameter completion: Async callback with retrived data
     */
    public func getMeta(handler: (locationMeta: LocationMeta?) -> Void) {
        // Reverse geocode stored coordinates
        CLGeocoder().reverseGeocodeLocation(
            CLLocation(latitude: self.coordinate.latitude, longitude: self.coordinate.longitude)) {
                placemarks, error in
                // Validate values
                guard let mark = placemarks?[0] where error == nil else {
                    return handler(locationMeta: nil)
                }
                
                // Get timezone if applicable
                var timezone: String?
                if mark.description != "" {
                    let desc = mark.description
                    
                    // Extract timezone description
                    if let regex = try? NSRegularExpression(
                        pattern: "identifier = \"([a-z]*\\/[a-z]*_*[a-z]*)\"",
                        options: .CaseInsensitive),
                        let result = regex.firstMatchInString(desc, options: [], range: NSMakeRange(0, desc.characters.count)) {
                            let tz = (desc as NSString).substringWithRange(result.rangeAtIndex(1))
                            timezone = tz.stringByReplacingOccurrencesOfString("_", withString: " ")
                    }
                }
                
                // Process callback
                handler(locationMeta: LocationMeta(
                    coordinates: (self.coordinate.latitude, self.coordinate.longitude),
                    locality: mark.locality,
                    country: mark.country,
                    countryCode: mark.ISOcountryCode,
                    timezone: timezone,
                    administrativeArea: mark.administrativeArea))
        }
    }
    
}<commit_msg>Fixed possible memory retain cycle.<commit_after>//
//  CLLocation.swift
//  ZamzamKit
//
//  Created by <NAME> on 2/17/16.
//  Copyright © 2016 Zamzam. All rights reserved.
//
import Foundation
import CoreLocation

public extension CLLocation {
    
    /**
     Retrieves location name for a place
     
     - parameter coordinates: Latitude and longitude] coordinates
     - parameter completion: Async callback with retrived data
     */
    public func getMeta(handler: (locationMeta: LocationMeta?) -> Void) {
        // Reverse geocode stored coordinates
        CLGeocoder().reverseGeocodeLocation(
            CLLocation(latitude: self.coordinate.latitude, longitude: self.coordinate.longitude)) {
                [weak self] placemarks, error in
                // Validate values
                guard let mark = placemarks?[0] where error == nil else {
                    return handler(locationMeta: nil)
                }
                
                // Get timezone if applicable
                var timezone: String?
                if mark.description != "" {
                    let desc = mark.description
                    
                    // Extract timezone description
                    if let regex = try? NSRegularExpression(
                        pattern: "identifier = \"([a-z]*\\/[a-z]*_*[a-z]*)\"",
                        options: .CaseInsensitive),
                        let result = regex.firstMatchInString(desc, options: [], range: NSMakeRange(0, desc.characters.count)) {
                            let tz = (desc as NSString).substringWithRange(result.rangeAtIndex(1))
                            timezone = tz.stringByReplacingOccurrencesOfString("_", withString: " ")
                    }
                }
                
                // COnstruct meta if reference still available
                var locationMeta: LocationMeta? = nil
                if self != nil {
                    locationMeta = LocationMeta(
                        coordinates: (self!.coordinate.latitude, self!.coordinate.longitude),
                        locality: mark.locality,
                        country: mark.country,
                        countryCode: mark.ISOcountryCode,
                        timezone: timezone,
                        administrativeArea: mark.administrativeArea)
                }
                
                // Process callback
                handler(locationMeta: locationMeta)
        }
    }
    
}
{'fraction_non_alphanumeric': 0.08651997436445204, 'fraction_numerical': 0.005127109591967528, 'mean_word_length': 1.4284232365145229, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3292510', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1061, 'n_words': 279}