<commit_before>//
//  SourceEditorCommand.swift
//  CleanClosure
//
//  Created by <NAME> on 6/18/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import XcodeKit

extension NSString {
    // Remove the given chracters in the range from the string.
    func remove(characters: [Character], in range: NSRange) -> NSString {
        var cleanedString = self
        for char in characters {
            cleanedString = cleanedString.replacingOccurrences(of: String(char), with: "", options: .caseInsensitiveSearch, range: range)
        }
        return cleanedString
    }
}

class SourceEditorCommand: NSObject, XCSourceEditorCommand {
    
    func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void {
        var updatedLineIndexes = [Int]()
        
        // Find lines that contain a closure syntax
        for lineIndex in 0 ..< invocation.buffer.lines.count {
            let line = invocation.buffer.lines[lineIndex] as! NSString
            do {
                let regex = try RegularExpression(pattern: "\\{.*\\(.+\\).+in", options: .caseInsensitive)
                let range = NSRange(location: 0, length: line.length)
                let results = regex.matches(in: line as String, options: .reportProgress, range: range)
                // When a closure is found, clean up its syntax
                _ = results.map { result in
                    let cleanLine = line.remove(characters: ["(", ")"], in: result.range)
                    updatedLineIndexes.append(lineIndex)
                    invocation.buffer.lines[lineIndex] = cleanLine
                }
            } catch {
                completionHandler(error as NSError)
            }
        }
        
        // If at least a line was changed, create an array of changes and pass it to the buffer selections.
        if updatedLineIndexes.count > 0 {
            let updatedSelections: [XCSourceTextRange] = updatedLineIndexes.map { lineIndex in
                let lineSelection = XCSourceTextRange()<commit_msg>Simplify range syntax<commit_after>//
//  SourceEditorCommand.swift
//  CleanClosure
//
//  Created by <NAME> on 6/18/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import XcodeKit

extension NSString {
    // Remove the given chracters in the range from the string.
    func remove(characters: [Character], in range: NSRange) -> NSString {
        var cleanedString = self
        for char in characters {
            cleanedString = cleanedString.replacingOccurrences(of: String(char), with: "", options: .caseInsensitiveSearch, range: range)
        }
        return cleanedString
    }
}

class SourceEditorCommand: NSObject, XCSourceEditorCommand {
    
    func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void {
        var updatedLineIndexes = [Int]()
        
        // Find lines that contain a closure syntax
        for lineIndex in 0 ..< invocation.buffer.lines.count {
            let line = invocation.buffer.lines[lineIndex] as! NSString
            do {
                let regex = try RegularExpression(pattern: "\\{.*\\(.+\\).+in", options: .caseInsensitive)
                let range = NSRange(0 ..< line.length)
                let results = regex.matches(in: line as String, options: .reportProgress, range: range)
                // When a closure is found, clean up its syntax
                _ = results.map { result in
                    let cleanLine = line.remove(characters: ["(", ")"], in: result.range)
                    updatedLineIndexes.append(lineIndex)
                    invocation.buffer.lines[lineIndex] = cleanLine
                }
            } catch {
                completionHandler(error as NSError)
            }
        }
        
        // If at least a line was changed, create an array of changes and pass it to the buffer selections.
        if updatedLineIndexes.count > 0 {
            let updatedSelections: [XCSourceTextRange] = updatedLineIndexes.map { lineIndex in
                let lineSelection = XCSourceTextRange()
{'fraction_non_alphanumeric': 0.09399855386840203, 'fraction_numerical': 0.005784526391901663, 'mean_word_length': 2.1156156156156154, 'pattern_counts': {'":': 0, '<': 10, '<?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': '7134637', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1049, 'n_words': 331}