<commit_before>//
//  Variable.swift
//  Stencil
//
//  Created by <NAME> on 23/10/2014.
//  Copyright (c) 2014 Cocode. All rights reserved.
//

import Foundation

public struct Variable : Equatable {
    public let variable:String

    public init(_ variable:String) {
        self.variable = variable
    }

    private func lookup() -> [String] {
        return variable.componentsSeparatedByString(".")
    }

    public func resolve(context:Context) -> AnyObject? {
        var current:AnyObject? = context

        if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) {
            return variable.substringWithRange(variable.startIndex.successor() ..< variable.endIndex.predecessor())
        }

        for bit in lookup() {
            if let context = current as? Context {
                current = context[bit]
            } else if let dictionary = current as? Dictionary<String, AnyObject> {
                current = dictionary[bit]
            } else if let array = current as? [AnyObject] {
                if let index = bit.toInt() {
                    current = array[index]
                } else if bit == "first" {
                    current = array.first
                } else if bit == "last" {
                    current = array.last
                }
            } else if let object = current as? NSObject {
                current = object.valueForKey(bit)
            } else {
                return nil
            }
        }

        return current
    }
}<commit_msg>[Variable] Match .count on arrays<commit_after>//
//  Variable.swift
//  Stencil
//
//  Created by <NAME> on 23/10/2014.
//  Copyright (c) 2014 Cocode. All rights reserved.
//

import Foundation

public struct Variable : Equatable {
    public let variable:String

    public init(_ variable:String) {
        self.variable = variable
    }

    private func lookup() -> [String] {
        return variable.componentsSeparatedByString(".")
    }

    public func resolve(context:Context) -> AnyObject? {
        var current:AnyObject? = context

        if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) {
            return variable.substringWithRange(variable.startIndex.successor() ..< variable.endIndex.predecessor())
        }

        for bit in lookup() {
            if let context = current as? Context {
                current = context[bit]
            } else if let dictionary = current as? Dictionary<String, AnyObject> {
                current = dictionary[bit]
            } else if let array = current as? [AnyObject] {
                if let index = bit.toInt() {
                    current = array[index]
                } else if bit == "first" {
                    current = array.first
                } else if bit == "last" {
                    current = array.last
                } else if bit == "count" {
                    current = countElements(array)
                }
            } else if let object = current as? NSObject {
                current = object.valueForKey(bit)
            } else {
                return nil
            }
        }

        return current
    }
}
{'fraction_non_alphanumeric': 0.11275415896487985, 'fraction_numerical': 0.0073937153419593345, 'mean_word_length': 1.6614754098360656, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1839066', 'n_tokens_mistral': 882, 'n_tokens_neox': 813, 'n_words': 232}