<commit_before>//
//  BasicJSON.swift
//  BasicJSON
//
//  Created by <NAME> on 20/04/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public enum JSONError:LocalizedError {
    case dataDecodingErrorUndecipherable
    case dataDecodingError(stringDecoded:String)
    case wrongBaseTypeForBuilding(expectedType:String)
    
    
    public var errorDescription: String? {
        switch self {
        case .dataDecodingErrorUndecipherable:
            return "Error decoding data, undecipherable"
        case .dataDecodingError(stringDecoded: let decoded):
            return "Error decoding data \(decoded)"
        case .wrongBaseTypeForBuilding(expectedType: let type):
            return "Wrong base type for building objects. Expected: \(type)"
        }
    }
}

public typealias RawJSON = [String:Any]
public typealias PureJSONValue = [String:JSONRepresentable]


public struct PureJSON {
    public let value:PureJSONValue
    
    init() {
        value = PureJSONValue()
    }
    
    init(raw:RawJSON) {
        value = JSON.purify(raw: raw)
    }
    
    public subscript(key: String) -> JSONRepresentable {
        get {
            if let value = self.value[key] {
                return value
            }
            return ""
        }
    }
    
    
}


protocol Convertible {
    var stringConverted:String { get }
    var doubleConverted:Double { get }
    var intConverted:Int { get }
    var boolConverted:Bool { get }
    
}

extension Convertible {
    var stringConverted:String { return "" }
    var doubleConverted:Double { return 0 }
    var intConverted:Int { return 0 }
    var boolConverted:Bool { return false }
}

extension NSString:Convertible {
    var stringConverted: String {
        return String(self)
    }
}

extension NSNumber:Convertible {
    var doubleConverted:Double {
        return Double(self)
    }
    var intConverted:Int {
        return Int(self)<commit_msg>Added convertibility to strings<commit_after>//
//  BasicJSON.swift
//  BasicJSON
//
//  Created by <NAME> on 20/04/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public enum JSONError:LocalizedError {
    case dataDecodingErrorUndecipherable
    case dataDecodingError(stringDecoded:String)
    case wrongBaseTypeForBuilding(expectedType:String)
    
    
    public var errorDescription: String? {
        switch self {
        case .dataDecodingErrorUndecipherable:
            return "Error decoding data, undecipherable"
        case .dataDecodingError(stringDecoded: let decoded):
            return "Error decoding data \(decoded)"
        case .wrongBaseTypeForBuilding(expectedType: let type):
            return "Wrong base type for building objects. Expected: \(type)"
        }
    }
}

public typealias RawJSON = [String:Any]
public typealias PureJSONValue = [String:JSONRepresentable]


public struct PureJSON {
    public let value:PureJSONValue
    
    init() {
        value = PureJSONValue()
    }
    
    init(raw:RawJSON) {
        value = JSON.purify(raw: raw)
    }
    
    public subscript(key: String) -> JSONRepresentable {
        get {
            if let value = self.value[key] {
                return value
            }
            return ""
        }
    }
    
    
}


protocol Convertible {
    var stringConverted:String { get }
    var doubleConverted:Double { get }
    var intConverted:Int { get }
    var boolConverted:Bool { get }
    
}

extension Convertible {
    var stringConverted:String { return "" }
    var doubleConverted:Double { return 0 }
    var intConverted:Int { return 0 }
    var boolConverted:Bool { return false }
}

extension NSString:Convertible {
    var stringConverted: String {
        return String(self)
    }
    var intConverted:Int {
        return self.integerValue
    }
    var doubleConverted:Double {
        return self.doubleValue
    }
    var boolConverted:Bool {
        return self.boolValue
    }
}

extension NSNumber:Convertible {
    var doubleConverted:Double {
        return Double(self)
    }
    var intConverted:Int {
        return Int(self)
{'fraction_non_alphanumeric': 0.0825242718446602, 'fraction_numerical': 0.006796116504854369, 'mean_word_length': 2.4086021505376345, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '629885', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1164, 'n_words': 298}