<commit_before>//
//  STPPhoneNumberValidator.swift
//  Stripe
//
//  Created by <NAME> on 10/16/15.
//  Copyright © 2015 Stripe, Inc. All rights reserved.
//

import Foundation

class STPPhoneNumberValidator: NSObject {
  class func stringIsValidPartialPhoneNumber(_ string: String) -> Bool {
    return self.stringIsValidPartialPhoneNumber(string, forCountryCode: nil)
  }

  class func stringIsValidPhoneNumber(_ string: String) -> Bool {
    if string == "" {
      return false
    }
    return self.stringIsValidPhoneNumber(string, forCountryCode: nil)
  }

  class func stringIsValidPartialPhoneNumber(
    _ string: String,
    forCountryCode nillableCode: String?
  ) -> Bool {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)

    if countryCode == "US" {
      return STPCardValidator.sanitizedNumericString(for: string).count <= 10
    } else {
      return true
    }
  }

  class func stringIsValidPhoneNumber(
    _ string: String,
    forCountryCode nillableCode: String?
  ) -> Bool {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)

    if countryCode == "US" {
      return STPCardValidator.sanitizedNumericString(for: string).count == 10
    } else {
      return true
    }
  }

  @objc(formattedSanitizedPhoneNumberForString:) class func formattedSanitizedPhoneNumber(
    for string: String
  ) -> String {
    return self.formattedSanitizedPhoneNumber(
      for: string,
      forCountryCode: nil)
  }

  @objc(formattedSanitizedPhoneNumberForString:forCountryCode:)
  class func formattedSanitizedPhoneNumber(
    for string: String,
    forCountryCode nillableCode: String?
  ) -> String {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)
    let sanitized = STPCardValidator.sanitizedNumericString(for: string)
    return self.formattedPhoneNumber(
      for: sanitized,
      forCountryCode: countryCode)
  }

  @objc(formattedRedactedPhoneNumberForString:) class func formattedRedactedPhoneNumber(
    for string: String
  ) -> String {
    return self.formattedRedactedPhoneNumber(
      for: string,
      forCountryCode: nil)
  }

  @objc(formattedRedactedPhoneNumberForString:forCountryCode:)
  class func formattedRedactedPhoneNumber(
    for string: String,
    forCountryCode nillableCode: String?
  ) -> String {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)
    let scanner = Scanner(string: string)
    var prefix: NSString? = NSString()
    scanner.scanUpTo("*", into: &prefix)
    var number = (string as NSString).replacingOccurrences(of: (prefix ?? "") as String, with: "")
    number = number.replacingOccurrences(of: "*", with: "•")
    number = self.formattedPhoneNumber(
      for: number,
      forCountryCode: countryCode)
    return "\(prefix ?? "") \(number)"
  }

  class func countryCodeOrCurrentLocaleCountry(from nillableCode: String?) -> String {
    var countryCode = nillableCode
    if countryCode == nil {<commit_msg>Fix a compiler warning on Catalyst<commit_after>//
//  STPPhoneNumberValidator.swift
//  Stripe
//
//  Created by <NAME> on 10/16/15.
//  Copyright © 2015 Stripe, Inc. All rights reserved.
//

import Foundation

class STPPhoneNumberValidator: NSObject {
  class func stringIsValidPartialPhoneNumber(_ string: String) -> Bool {
    return self.stringIsValidPartialPhoneNumber(string, forCountryCode: nil)
  }

  class func stringIsValidPhoneNumber(_ string: String) -> Bool {
    if string == "" {
      return false
    }
    return self.stringIsValidPhoneNumber(string, forCountryCode: nil)
  }

  class func stringIsValidPartialPhoneNumber(
    _ string: String,
    forCountryCode nillableCode: String?
  ) -> Bool {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)

    if countryCode == "US" {
      return STPCardValidator.sanitizedNumericString(for: string).count <= 10
    } else {
      return true
    }
  }

  class func stringIsValidPhoneNumber(
    _ string: String,
    forCountryCode nillableCode: String?
  ) -> Bool {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)

    if countryCode == "US" {
      return STPCardValidator.sanitizedNumericString(for: string).count == 10
    } else {
      return true
    }
  }

  @objc(formattedSanitizedPhoneNumberForString:) class func formattedSanitizedPhoneNumber(
    for string: String
  ) -> String {
    return self.formattedSanitizedPhoneNumber(
      for: string,
      forCountryCode: nil)
  }

  @objc(formattedSanitizedPhoneNumberForString:forCountryCode:)
  class func formattedSanitizedPhoneNumber(
    for string: String,
    forCountryCode nillableCode: String?
  ) -> String {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)
    let sanitized = STPCardValidator.sanitizedNumericString(for: string)
    return self.formattedPhoneNumber(
      for: sanitized,
      forCountryCode: countryCode)
  }

  @objc(formattedRedactedPhoneNumberForString:) class func formattedRedactedPhoneNumber(
    for string: String
  ) -> String {
    return self.formattedRedactedPhoneNumber(
      for: string,
      forCountryCode: nil)
  }

  @objc(formattedRedactedPhoneNumberForString:forCountryCode:)
  class func formattedRedactedPhoneNumber(
    for string: String,
    forCountryCode nillableCode: String?
  ) -> String {
    let countryCode = self.countryCodeOrCurrentLocaleCountry(from: nillableCode)
    let scanner = Scanner(string: string)
    var prefix: NSString? = NSString()
    if #available(iOS 13.0, *) {
      prefix = scanner.scanUpToString("*") as NSString?
    } else {
      #if !TARGET_OS_MACCATALYST
      scanner.scanUpTo("*", into: &prefix)
      #endif
    }
    var number = (string as NSString).replacingOccurrences(of: (prefix ?? "") as String, with: "")
    number = number.replacingOccurrences(of: "*", with: "•")
    number = self.formattedPhoneNumber(
      for: number,
      forCountryCode: countryCode)
    return "\(prefix ?? "") \(number)"
  }

  class func countryCodeOrCurrentLocaleCountry(from nillableCode: String?) -> String {
    var countryCode = nillableCode
    if countryCode == nil {
{'fraction_non_alphanumeric': 0.09440051637889302, 'fraction_numerical': 0.005002420526060997, 'mean_word_length': 3.778720123361604, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '4921143', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1823, 'n_words': 424}