<commit_before>//
//  Regex.swift
//  Cent
//
//  Created by <NAME> on 10/21/14.
//  Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved.
//

import Foundation
import Dollar

let RegexEscapePattern = "[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]"
let RegexPatternRegex = Regex(RegexEscapePattern)

public class Regex {
    
    let expression: NSRegularExpression
    let pattern: String
    
    init(_ pattern: String) {
        self.pattern = pattern
        var error: NSError?
        self.expression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error)!
    }
    
    public func matches(testStr: String) -> [AnyObject] {
        let matches = self.expression.matchesInString(testStr, options: nil, range:NSMakeRange(0, countElements(testStr)))
        return matches
    }
    
    public func rangeOfFirstMatch(testStr: String) -> NSRange {
        return self.expression.rangeOfFirstMatchInString(testStr, options: nil, range:NSMakeRange(0, countElements(testStr)))
    }
    
    public func test(testStr: String) -> Bool {
        let matches = self.matches(testStr)
        return matches.count > 0
    }
    
    public class func escapeStr(str: String) -> String {
        let matches = RegexPatternRegex.matches(str)
        var charArr = [Character](str)
        var strBuilder = [Character]()
        var i = 0<commit_msg>Make initializer public<commit_after>//
//  Regex.swift
//  Cent
//
//  Created by <NAME> on 10/21/14.
//  Copyright (c) 2014 Encore Dev Labs LLC. All rights reserved.
//

import Foundation
import Dollar

let RegexEscapePattern = "[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]"
let RegexPatternRegex = Regex(RegexEscapePattern)

public class Regex {
    
    let expression: NSRegularExpression
    let pattern: String
    
    public init(_ pattern: String) {
        self.pattern = pattern
        var error: NSError?
        self.expression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error)!
    }
    
    public func matches(testStr: String) -> [AnyObject] {
        let matches = self.expression.matchesInString(testStr, options: nil, range:NSMakeRange(0, countElements(testStr)))
        return matches
    }
    
    public func rangeOfFirstMatch(testStr: String) -> NSRange {
        return self.expression.rangeOfFirstMatchInString(testStr, options: nil, range:NSMakeRange(0, countElements(testStr)))
    }
    
    public func test(testStr: String) -> Bool {
        let matches = self.matches(testStr)
        return matches.count > 0
    }
    
    public class func escapeStr(str: String) -> String {
        let matches = RegexPatternRegex.matches(str)
        var charArr = [Character](str)
        var strBuilder = [Character]()
        var i = 0
{'fraction_non_alphanumeric': 0.13285457809694792, 'fraction_numerical': 0.010053859964093357, 'mean_word_length': 2.6088082901554404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6847377', 'n_tokens_mistral': 871, 'n_tokens_neox': 824, 'n_words': 212}