<commit_before>//
//  String.swift
//  Syml
//
//  Created by <NAME> on 26/08/2015.
//  Copyright © 2015 Inquisitive Software. All rights reserved.
//

import Foundation


infix operator =~ {}


internal func =~ (string: String, pattern: String) -> Bool {
	do {
		let regex = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
		let matches = regex.numberOfMatchesInString(string, options: [], range:NSRangeOfString(string))
		return matches > 0
	} catch {}
	
	return false
}



func NSRangeOfString(string: NSString!) -> NSRange {
	let range = NSRange(location: 0, length:string.length)
	return range
}


extension String {
	
	func numberOfWords() -> UInt {
		var numberOfWords: UInt = 0
		let searchRange = self.startIndex..<self.endIndex
		
		self.enumerateSubstringsInRange(searchRange, options: [NSStringEnumerationOptions.ByWords, NSStringEnumerationOptions.SubstringNotRequired]) { (_, _, _, _) -> () in
			numberOfWords++
		}
		
		return numberOfWords
	}
	
	<commit_msg>Expanded numberOf* methods on String<commit_after>//
//  String.swift
//  Syml
//
//  Created by <NAME> on 26/08/2015.
//  Copyright © 2015 Inquisitive Software. All rights reserved.
//

import Foundation


infix operator =~ {}


internal func =~ (string: String, pattern: String) -> Bool {
	do {
		let regex = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
		let matches = regex.numberOfMatchesInString(string, options: [], range:NSRangeOfString(string))
		return matches > 0
	} catch {}
	
	return false
}



func NSRangeOfString(string: NSString!) -> NSRange {
	let range = NSRange(location: 0, length:string.length)
	return range
}


extension String {
	
	func numberOfWords() -> UInt {
		var numberOfWords: UInt = 0
		let searchRange = self.startIndex..<self.endIndex
		
		self.enumerateSubstringsInRange(searchRange, options: [NSStringEnumerationOptions.ByWords, NSStringEnumerationOptions.SubstringNotRequired]) { (_, _, _, _) -> () in
			numberOfWords++
		}
		
		return numberOfWords
	}
	
	
	func numberOfSentences() -> UInt {
		var numberOfSentences: UInt = 0
		let searchRange = self.startIndex..<self.endIndex
		
		self.enumerateSubstringsInRange(searchRange, options: [NSStringEnumerationOptions.BySentences, NSStringEnumerationOptions.SubstringNotRequired]) { (_, _, _, _) -> () in
			numberOfSentences++
		}
		
		return numberOfSentences
	}
	
	
	func numberOfParagraphs() -> UInt {
		var numberOfParagraphs: UInt = 0
		let searchRange = self.startIndex..<self.endIndex
		
		self.enumerateSubstringsInRange(searchRange, options: [NSStringEnumerationOptions.ByParagraphs, NSStringEnumerationOptions.SubstringNotRequired]) { (_, _, _, _) -> () in
			numberOfParagraphs++
		}
		
		return numberOfParagraphs
	}
	
	
	func numberOfCharacters() -> UInt {
		return UInt(self.characters.count)
	}
	
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.01107649705780547, 'mean_word_length': 4.216606498194946, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, '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': '3478392', 'n_tokens_mistral': 1016, 'n_tokens_neox': 872, 'n_words': 199}