<commit_before>//
//  CommandLine+Utilities.swift
//  swiftlets
//
//  Created by <NAME> on 7/16/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import Foundation

private let FLAG_TOKEN:String = "-"

extension CommandLine {
    ///Returns the index of the flag in the arguments, nil if not found
    public static func flagIndex(flag: String) -> Int? {
        return flagIndex(aliases: [flag])
    }
    
    ///Returns the index of the first alias found in the arguments, nil if none found
    public static func flagIndex(aliases: Set<String>) -> Int? {
        return CommandLine.arguments.firstIndex(where:{aliases.contains($0)});
    }
    
    ///Returns true if the flag is found in the arguments
    public static func flagExists(flag: String) -> Bool {
        return flagExists(aliases: [flag])
    }
    
    ///Returns true if any of the flag aliases are found in the arguments
    public static func flagExists(aliases: Set<String>) -> Bool {
        return flagIndex(aliases: aliases) != nil;
    }
    
    ///Fetch the slice of arguments associated with a flag
    /// Returns nil if flag not found
    public static func flagValues(flag: String) -> ArraySlice<String>? {
        return flagValues(aliases: [flag])
    }
    
    ///Fetch the slice of arguments associated with a set of flag aliases
    /// Returns nil if none of the aliases are found
    public static func flagValues(aliases: Set<String>) -> ArraySlice<String>? {
        guard let flag = flagIndex(aliases: aliases) else {
            return nil;
        }
        
        var slice = CommandLine.arguments[flag...].dropFirst()        
        if let nextFlag = slice.firstIndex(where: {$0.hasPrefix(FLAG_TOKEN)}) {
            slice = slice.dropLast(slice.distance(from: nextFlag, to: slice.endIndex))
        }
        
        return slice
    }
    
    ///Returns the set of flags in the arguments which are not present in the set of expected flags
    /// This is a utility method to test for unexpected flags on the command line.
    public static func findUnknown(expected: Set<String>) -> Set<String> {
        return CommandLine.allFlags.subtracting(expected)
    }
    
    ///Returns the set of flags in the arguments which are not present in the set of required flags
    /// This is a utility method to test for the presence of required flags on the command line.
    public static func findMissing(required: Set<String>) -> Set<String> {
        return required.subtracting(CommandLine.allFlags)
    }
    
    ///Returns slice of arguments up to the first flag
    public static func head() -> ArraySlice<String> {
        guard let firstFlag = CommandLine.arguments.firstIndex(where: {$0.hasPrefix(FLAG_TOKEN)}) else {
            return CommandLine.arguments[..<CommandLine.arguments.endIndex].dropFirst()
        }
        return CommandLine.arguments[..<firstFlag].dropFirst()
    }
    
    ///Returns slice of arguments up to the first flag
    public static func tail() -> ArraySlice<String> {
        guard let lastFlag = CommandLine.arguments.lastIndex(where: {$0.hasPrefix(FLAG_TOKEN)}) else {
            return CommandLine.arguments[..<CommandLine.arguments.endIndex].dropFirst()
        }
        return CommandLine.arguments[lastFlag...].dropFirst()
    }
    
    ///Returns the set of all flags found in the arguments.
    /// Order is not guaranteed, duplicates will be removed.
    public static var allFlags: Set<String> {
        get {
            return Set(CommandLine.arguments.filter({$0.hasPrefix(FLAG_TOKEN)}))
        }
    }
}
<commit_msg>Code cleanup<commit_after>//
//  CommandLine+Utilities.swift
//  swiftlets
//
//  Created by <NAME> on 7/16/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import Foundation

private let FLAG_TOKEN:String = "-"

extension CommandLine {
    ///Returns the index of the flag in the arguments, nil if not found
    public static func flagIndex(flag: String) -> Int? {
        return flagIndex(aliases: [flag])
    }
    
    ///Returns the index of the first alias found in the arguments, nil if none found
    public static func flagIndex(aliases: Set<String>) -> Int? {
        return CommandLine.arguments.firstIndex(where:{aliases.contains($0)});
    }
    
    ///Returns true if the flag is found in the arguments
    public static func flagExists(flag: String) -> Bool {
        return flagExists(aliases: [flag])
    }
    
    ///Returns true if any of the flag aliases are found in the arguments
    public static func flagExists(aliases: Set<String>) -> Bool {
        return flagIndex(aliases: aliases) != nil;
    }
    
    ///Fetch the slice of arguments associated with a flag
    /// Returns nil if flag not found
    public static func flagValues(flag: String) -> ArraySlice<String>? {
        return flagValues(aliases: [flag])
    }
    
    ///Fetch the slice of arguments associated with a set of flag aliases
    /// Returns nil if none of the aliases are found
    public static func flagValues(aliases: Set<String>) -> ArraySlice<String>? {
        guard let flag = flagIndex(aliases: aliases) else {
            return nil;
        }
        
        var slice = CommandLine.arguments[flag...].dropFirst()        
        if let nextFlag = slice.firstIndex(where: {$0.hasPrefix(FLAG_TOKEN)}) {
            slice = slice.dropLast(slice.distance(from: nextFlag, to: slice.endIndex))
        }
        
        return slice
    }
    
    ///Returns the set of flags in the arguments which are not present in the set of expected flags
    /// This is a utility method to test for unexpected flags on the command line.
    public static func findUnknown(expected: Set<String>) -> Set<String> {
        return CommandLine.allFlags.subtracting(expected)
    }
    
    ///Returns the set of flags in the arguments which are not present in the set of required flags
    /// This is a utility method to test for the presence of required flags on the command line.
    public static func findMissing(required: Set<String>) -> Set<String> {
        return required.subtracting(CommandLine.allFlags)
    }
    
    ///Returns slice of arguments up to the first flag
    /// This a utility method to access any non-flag related parameters that appear at the beginning of the list
    public static func head() -> ArraySlice<String> {
        guard let firstFlag = CommandLine.arguments.firstIndex(where: {$0.hasPrefix(FLAG_TOKEN)}) else {
            return CommandLine.arguments[..<CommandLine.arguments.endIndex].dropFirst()
        }
        return CommandLine.arguments[..<firstFlag].dropFirst()
    }
    
    ///Returns slice of arguments after the last flag
    /// This a utility method to access any non-flag related parameters that appear at the end of the list
    public static func tail() -> ArraySlice<String> {
        guard let lastFlag = CommandLine.arguments.lastIndex(where: {$0.hasPrefix(FLAG_TOKEN)}) else {
            return CommandLine.arguments[..<CommandLine.arguments.endIndex].dropFirst()
        }
        return CommandLine.arguments[lastFlag...].dropFirst()
    }
    
    ///Returns the set of all flags found in the arguments.
    /// Order is not guaranteed, duplicates will be removed.
    public static var allFlags: Set<String> {
        get {
            return Set(CommandLine.arguments.filter({$0.hasPrefix(FLAG_TOKEN)}))
        }
    }
}

{'fraction_non_alphanumeric': 0.09696641386782232, 'fraction_numerical': 0.003791982665222102, 'mean_word_length': 2.6041971693509027, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 51, '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': '1349205', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1948, 'n_words': 716}