<commit_before>//
//  VerbalExpressions.swift
//  VerbalExpressions
//
//  Created by <NAME> on 04/06/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation

func VerEx(options: NSRegularExpressionOptions = nil) -> VerbalExpressions {
    return VerbalExpressions(options: options)
}

class VerbalExpressions {
    // stored properties
    var pattern: String = ""
    var options: NSRegularExpressionOptions!
    
    // computed properties
    var regex: NSRegularExpression {
    return NSRegularExpression(pattern: pattern, options: options, error: nil)
    }
    
    // class methods
    class func escape(str: String) -> String {
        return NSRegularExpression.escapedPatternForString(str)
    }
    
    
    // initializers
    init(options: NSRegularExpressionOptions = nil) {
        self.options = options
    }
    
    
    // instance methods
    func startOfLine() -> Self {
        pattern += "^"
        
        return self
    }
    
    func endOfLine() -> Self {
        pattern += "$"
        
        return self
    }
    
    func then(str: String) -> Self {
        pattern += "(?:\(VerbalExpressions.escape(str)))"
        
        return self
    }
    
    // alias for then
    func find(str: String) -> Self {
        return self.then(str)
    }
    
    func maybe(str: String) -> Self {
        pattern += "(?:\(VerbalExpressions.escape(str)))?"
        
        return self
    }
    
    func something() -> Self {
        pattern += "(?:.+)"
        
        return self
    }
    
    func somethingBut(str: String) -> Self {
        pattern += "(?:[^\(VerbalExpressions.escape(str))]+)"
        
        return self
    }
    
    func anything() -> Self {
        pattern += "(?:.*)"
        
        return self
    }
    
    func anythingBut(str: String) -> Self {
        pattern += "(?:[^\(VerbalExpressions.escape(str))]*)"
        
        return self
    }
    
    func anyOf(str: String) -> Self {
        pattern += "(?:[\(VerbalExpressions.escape(str))])"
        
        return self
    }
    
    func any(str: String) -> Self {
        return self.anyOf(str)
    }
    
    func linebreak() -> Self {
        pattern += "(?:(?:\n)|(?:\r\n))"
        
        return self
    }
    
    // alias for linebreak
    func br() -> Self {
        return self.linebreak()
    }
    
    func tab() -> Self {
        pattern += "\t"
        
        return self
    }
    
    func word() -> Self {
        pattern += "\\w+"
        
        return self
    }
    
    func test(str: String, options: NSMatchingOptions = nil) -> Bool {
        let range = NSRange(location: 0, length: countElements(str))
        let result = self.regex.firstMatchInString(str, options: options, range: range)
        
        if result {
            return result.range.location != NSNotFound
        }
        
        return false
    }
    
}<commit_msg>Improve swift coding style<commit_after>//
//  VerbalExpressions.swift
//  VerbalExpressions
//
//  Created by <NAME> on 04/06/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation

func VerEx(options: NSRegularExpressionOptions = nil) -> VerbalExpressions {
    return VerbalExpressions(options: options)
}

class VerbalExpressions {
    // stored properties
    var pattern: String = ""
    var options: NSRegularExpressionOptions = nil

    // computed properties
    var regex: NSRegularExpression {
    return NSRegularExpression(pattern: pattern, options: options, error: nil)
    }

    // class methods
    class func escape(string: String) -> String {
        return NSRegularExpression.escapedPatternForString(string)
    }


    // initializers
    init(options: NSRegularExpressionOptions = nil) {
        self.options = options
    }


    // instance methods
    func startOfLine() -> Self {
        pattern += "^"

        return self
    }

    func endOfLine() -> Self {
        pattern += "$"

        return self
    }

    func then(string: String) -> Self {
        pattern += "(?:\(VerbalExpressions.escape(string)))"

        return self
    }

    // alias for then
    func find(string: String) -> Self {
        return then(string)
    }

    func maybe(string: String) -> Self {
        pattern += "(?:\(VerbalExpressions.escape(string)))?"

        return self
    }

    func something() -> Self {
        pattern += "(?:.+)"

        return self
    }

    func somethingBut(string: String) -> Self {
        pattern += "(?:[^\(VerbalExpressions.escape(string))]+)"

        return self
    }

    func anything() -> Self {
        pattern += "(?:.*)"

        return self
    }

    func anythingBut(string: String) -> Self {
        pattern += "(?:[^\(VerbalExpressions.escape(string))]*)"

        return self
    }

    func anyOf(string: String) -> Self {
        pattern += "(?:[\(VerbalExpressions.escape(string))])"

        return self
    }

    func any(string: String) -> Self {
        return anyOf(string)
    }

    func linebreak() -> Self {
        pattern += "(?:(?:\n)|(?:\r\n))"

        return self
    }

    // alias for linebreak
    func br() -> Self {
        return linebreak()
    }

    func tab() -> Self {
        pattern += "\t"

        return self
    }

    func word() -> Self {
        pattern += "\\w+"

        return self
    }

    func test(string: String, options: NSMatchingOptions = nil) -> Bool {
        let range = NSRange(location: 0, length: countElements(string))
        
        if let result = regex.firstMatchInString(string, options: options, range: range) {
            return result.range.location != NSNotFound
        }

        return false
    }

}
{'fraction_non_alphanumeric': 0.13028169014084506, 'fraction_numerical': 0.0038732394366197184, 'mean_word_length': 1.839080459770115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, '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': '1873800', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1614, 'n_words': 401}