<commit_before>//
//  Error.swift
//  SessionSwift
//
//  Created by aleksey on 14.10.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public protocol ErrorCodesList {
  
  static func allCodes() -> [ErrorCode]
  
}

public protocol ErrorContext {
  
  var rawValue: String { get }
  
}

public protocol ErrorCode {
  
  static var domain: String { get }
  var rawValue: String { get }
  
}

public struct Error: ErrorType {
  
  public var hashValue: Int {
    return (code.rawValue + domain).hashValue
  }
  
  public let domain: String
  public let code: ErrorCode
  public let context: ErrorContext?
  public let underlyingError: NSError?
  
  public init(code: ErrorCode, context: ErrorContext? = nil, underlyingError: NSError? = nil) {
    self.domain = code.dynamicType.domain
    self.code = code
    self.context = context
    self.underlyingError = underlyingError
  }
  
  public func localizedDescription() -> String {
    return NSLocalizedString(descriptionString(), comment: "")
  }
  
  public func fullDescription() -> String {
    return descriptionString() + ": " + localizedDescription()
  }
  
  private func descriptionString() -> String {
    
    var descriptionString = "\(domain).\(code)"
    if let context = context {
      descriptionString += ".\(context.rawValue)"
    }
    
    return descriptionString
  }
  
}

extension Error: Hashable, Equatable {
  
}

public func ==(a: Error, b: Error) -> Bool {
  return a.code == b.code
}

public func ==(a: ErrorCode, b: ErrorCode) -> Bool {
  return a.rawValue == b.rawValue && a.dynamicType.domain == b.dynamicType.domain
}<commit_msg>fixed bug in localization<commit_after>//
//  Error.swift
//  SessionSwift
//
//  Created by aleksey on 14.10.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public protocol ErrorCodesList {
  
  static func allCodes() -> [ErrorCode]
  
}

public protocol ErrorContext {
  
  var rawValue: String { get }
  
}

public protocol ErrorCode {
  
  static var domain: String { get }
  var rawValue: String { get }
  
}

public struct Error: ErrorType {
  
  public var hashValue: Int {
    return (code.rawValue + domain).hashValue
  }
  
  public let domain: String
  public let code: ErrorCode
  public let context: ErrorContext?
  public let underlyingError: NSError?
  
  public init(code: ErrorCode, context: ErrorContext? = nil, underlyingError: NSError? = nil) {
    self.domain = code.dynamicType.domain
    self.code = code
    self.context = context
    self.underlyingError = underlyingError
  }
  
  public func localizedDescription() -> String {
    return NSLocalizedString(descriptionString(), comment: "")
  }
  
  public func fullDescription() -> String {
    return descriptionString() + ": " + localizedDescription()
  }
  
  private func descriptionString() -> String {
    
    var descriptionString = "\(domain).\(code.rawValue)"
    if let context = context {
      descriptionString += ".\(context.rawValue)"
    }
    
    return descriptionString
  }
  
}

extension Error: Hashable, Equatable {
  
}

public func ==(a: Error, b: Error) -> Bool {
  return a.code == b.code
}

public func ==(a: ErrorCode, b: ErrorCode) -> Bool {
  return a.rawValue == b.rawValue && a.dynamicType.domain == b.dynamicType.domain
}
{'fraction_non_alphanumeric': 0.11292764153799577, 'fraction_numerical': 0.006055101422948834, 'mean_word_length': 3.04406364749082, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 17, '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': '1443800', 'n_tokens_mistral': 1028, 'n_tokens_neox': 997, 'n_words': 287}