<commit_before>import Foundation

/// The rule matches the host domain to a list of predefined regular expressions.
public class DomainListRule: Rule {
    private let adapterFactory: AdapterFactory

    public override var description: String {
        return "<DomainListRule>"
    }

    /// The list of regular expressions to match to.
    public var urls: [NSRegularExpression] = []

    /**
     Create a new `ListRule` instance.

     - parameter adapterFactory: The factory which builds a corresponding adapter when needed.
     - parameter urls:           The list of regular expressions to match. The regular expression is parsed by `NSRegularExpression(pattern: url, options: .CaseInsensitive)`.

     - throws: The error when parsing the regualar expressions.
     */
    public init(adapterFactory: AdapterFactory, urls: [String]) throws {
        self.adapterFactory = adapterFactory
        self.urls = try urls.map {
            try NSRegularExpression(pattern: $0, options: .CaseInsensitive)
        }
    }

    /**
     Match DNS request to this rule.

     - parameter session: The DNS session to match.
     - parameter type:    What kind of information is available.

     - returns: The result of match.
     */
    override func matchDNS(session: DNSSession, type: DNSSessionMatchType) -> DNSSessionMatchResult {
        if matchDomain(session.requestMessage.queries.first!.name) {
            if let _ = adapterFactory as? DirectAdapterFactory {
                return .Real
            }
            return .Fake
        }
        return .Pass
    }

    /**
     Match connect request to this rule.

     - parameter request: Connect request to match.

     - returns: The configured adapter if matched, return `nil` if not matched.
     */
    override func match(request: ConnectRequest) -> AdapterFactory? {
        if matchDomain(request.host) {
            return adapterFactory
        }
        return nil
    }

    private func matchDomain(name: String) -> Bool {
        for url in urls {
            if let _ = url.firstMatchInString(name, options: [], range: NSRange(location: 0, length: name.utf16.count)) {
                return true
            }
        }
        return false
    }
}
<commit_msg>Fix doc<commit_after>import Foundation

/// The rule matches the host domain to a list of predefined regular expressions.
public class DomainListRule: Rule {
    private let adapterFactory: AdapterFactory

    public override var description: String {
        return "<DomainListRule>"
    }

    /// The list of regular expressions to match to.
    public var urls: [NSRegularExpression] = []

    /**
     Create a new `DomainListRule` instance.

     - parameter adapterFactory: The factory which builds a corresponding adapter when needed.
     - parameter urls:           The list of regular expressions to match. The regular expression is parsed by `NSRegularExpression(pattern: url, options: .CaseInsensitive)`.

     - throws: The error when parsing the regualar expressions.
     */
    public init(adapterFactory: AdapterFactory, urls: [String]) throws {
        self.adapterFactory = adapterFactory
        self.urls = try urls.map {
            try NSRegularExpression(pattern: $0, options: .CaseInsensitive)
        }
    }

    /**
     Match DNS request to this rule.

     - parameter session: The DNS session to match.
     - parameter type:    What kind of information is available.

     - returns: The result of match.
     */
    override func matchDNS(session: DNSSession, type: DNSSessionMatchType) -> DNSSessionMatchResult {
        if matchDomain(session.requestMessage.queries.first!.name) {
            if let _ = adapterFactory as? DirectAdapterFactory {
                return .Real
            }
            return .Fake
        }
        return .Pass
    }

    /**
     Match connect request to this rule.

     - parameter request: Connect request to match.

     - returns: The configured adapter if matched, return `nil` if not matched.
     */
    override func match(request: ConnectRequest) -> AdapterFactory? {
        if matchDomain(request.host) {
            return adapterFactory
        }
        return nil
    }

    private func matchDomain(name: String) -> Bool {
        for url in urls {
            if let _ = url.firstMatchInString(name, options: [], range: NSRange(location: 0, length: name.utf16.count)) {
                return true
            }
        }
        return false
    }
}

{'fraction_non_alphanumeric': 0.07719767960731816, 'fraction_numerical': 0.00178491744756805, 'mean_word_length': 2.253265602322206, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3371146', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1104, 'n_words': 407}