<commit_before>//
//  PhoneNumber.swift
//  PhoneNumberKit
//
//  Created by <NAME> on 26/09/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public struct PhoneNumber {
    private(set) public var countryCode: UInt64
    private(set) public var nationalNumber: UInt64
    private(set) public var numberExtension: String?
    private(set) public var rawNumber: String
    private(set) public var leadingZero: Bool
    private(set) public var type: PNPhoneNumberType
}

public extension PhoneNumber {
    
    // Parse raw number (with default SIM region)
    public init(rawNumber: String) throws {
        let phoneNumberKit = PhoneNumberKit()
        let defaultRegion = phoneNumberKit.defaultRegionCode()
        try self.init(rawNumber: rawNumber, region : defaultRegion)
    }
    
    // Parse raw number with custom region
    public init(rawNumber: String, region: String) throws {
        let parser = PhoneNumberParser()
        self.rawNumber = rawNumber
        
        // Validations
        if (rawNumber.isEmpty) {
            throw PNParsingError.NotANumber
        } else if (rawNumber.characters.count > PNMaxInputStringLength) {
            throw PNParsingError.TooLong
        }
        
        // Possible number extraction
        var nationalNumber = parser.extractPossibleNumber(rawNumber)
        
        if (parser.isViablePhoneNumber(nationalNumber as String) == false) {
            throw PNParsingError.NotANumber<commit_msg>Uppercase region<commit_after>//
//  PhoneNumber.swift
//  PhoneNumberKit
//
//  Created by <NAME> on 26/09/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public struct PhoneNumber {
    private(set) public var countryCode: UInt64
    private(set) public var nationalNumber: UInt64
    private(set) public var numberExtension: String?
    private(set) public var rawNumber: String
    private(set) public var leadingZero: Bool
    private(set) public var type: PNPhoneNumberType
}

public extension PhoneNumber {
    
    // Parse raw number (with default SIM region)
    public init(rawNumber: String) throws {
        let phoneNumberKit = PhoneNumberKit()
        let defaultRegion = phoneNumberKit.defaultRegionCode()
        try self.init(rawNumber: rawNumber, region : defaultRegion)
    }
    
    // Parse raw number with custom region
    public init(rawNumber: String, region: String) throws {
        let region = region.uppercaseString
        let parser = PhoneNumberParser()
        self.rawNumber = rawNumber
        
        // Validations
        if (rawNumber.isEmpty) {
            throw PNParsingError.NotANumber
        } else if (rawNumber.characters.count > PNMaxInputStringLength) {
            throw PNParsingError.TooLong
        }
        
        // Possible number extraction
        var nationalNumber = parser.extractPossibleNumber(rawNumber)
        
        if (parser.isViablePhoneNumber(nationalNumber as String) == false) {
            throw PNParsingError.NotANumber
{'fraction_non_alphanumeric': 0.07745779543197617, 'fraction_numerical': 0.010592519033432638, 'mean_word_length': 2.6808769792935445, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7368681', 'n_tokens_mistral': 841, 'n_tokens_neox': 799, 'n_words': 235}