Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import PackageDescription

let package = Package(
name: "json-swift",
targets: [
Target(name: "JSONLib", dependencies: []),
Target(name: "ParserTestHarness", dependencies: ["JSONLib"]),
Target(name: "ParserPerfTestHarness", dependencies: ["JSONLib"])
]
name: "json-swift",
targets: [
Target(name: "JSONLib", dependencies: []),
Target(name: "ParserTestHarness", dependencies: ["JSONLib"]),
Target(name: "ParserPerfTestHarness", dependencies: ["JSONLib"]),
]
)
58 changes: 29 additions & 29 deletions Sources/JSONLib/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@

/// Represents error information for JSON parsing issues.
public final class JsonParserError: Swift.Error {
public typealias ErrorInfoDictionary = [String:String]
public typealias ErrorInfoDictionary = [String: String]

/// The error code used to differentiate between various error states.
public let code: Int
/// The error code used to differentiate between various error states.
public let code: Int

/// A string that is used to group errors into related error buckets.
public let domain: String
/// A string that is used to group errors into related error buckets.
public let domain: String

/// A place to store any custom information that needs to be passed along with the error instance.
public let userInfo: ErrorInfoDictionary?
/// A place to store any custom information that needs to be passed along with the error instance.
public let userInfo: ErrorInfoDictionary?


/// Initializes a new `Error` instance.
public init(code: Int, domain: String, userInfo: ErrorInfoDictionary?) {
self.code = code
self.domain = domain
self.userInfo = userInfo
}
/// Initializes a new `Error` instance.
public init(code: Int, domain: String, userInfo: ErrorInfoDictionary?) {
self.code = code
self.domain = domain
self.userInfo = userInfo
}
}

/// The standard keys used in `Error` and `userInfo`.
public struct ErrorKeys {
private init() {}
public static let LocalizedDescription = "NSLocalizedDescription"
public static let LocalizedFailureReason = "NSLocalizedFailureReason"
public static let LocalizedRecoverySuggestion = "NSLocalizedRecoverySuggestion"
public static let LocalizedRecoveryOptions = "NSLocalizedRecoveryOptions"
public static let RecoveryAttempter = "NSRecoveryAttempter"
public static let HelpAnchor = "NSHelpAnchor"
public static let StringEncoding = "NSStringEncoding"
public static let URL = "NSURL"
public static let FilePath = "NSFilePath"
private init() {}

public static let LocalizedDescription = "NSLocalizedDescription"
public static let LocalizedFailureReason = "NSLocalizedFailureReason"
public static let LocalizedRecoverySuggestion = "NSLocalizedRecoverySuggestion"
public static let LocalizedRecoveryOptions = "NSLocalizedRecoveryOptions"
public static let RecoveryAttempter = "NSRecoveryAttempter"
public static let HelpAnchor = "NSHelpAnchor"

public static let StringEncoding = "NSStringEncoding"
public static let URL = "NSURL"
public static let FilePath = "NSFilePath"
}

extension JsonParserError: CustomStringConvertible {
public var description: String {
return "Error code: \(self.code), domain: \(self.domain)\ninfo: \(String(describing: self.userInfo))"
}
public var description: String {
return
"Error code: \(self.code), domain: \(self.domain)\ninfo: \(String(describing: self.userInfo))"
}
}
33 changes: 16 additions & 17 deletions Sources/JSONLib/Functional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* ------------------------------------------------------------------------------------------ */

precedencegroup FunctionalPrecedence {
associativity: left
higherThan: MultiplicationPrecedence
associativity: left
higherThan: MultiplicationPrecedence
}

infix operator ⇒ : FunctionalPrecedence
Expand All @@ -16,13 +16,13 @@ infix operator ⇒ : FunctionalPrecedence
/// - parameter rhs: The value to apply to the function
/// - returns: The transformation of `rhs` using `lhs`.
public func ⇒ <A, B>(lhs: ((A) -> B)?, rhs: A?) -> B? {
if let lhs = lhs {
if let rhs = rhs {
return lhs(rhs)
}
}
return nil
if let lhs = lhs {
if let rhs = rhs {
return lhs(rhs)
}
}

return nil
}

/// Allows for a value to be transformed by a function, allowing for optionals.
Expand All @@ -31,13 +31,13 @@ public func ⇒ <A, B>(lhs: ((A) -> B)?, rhs: A?) -> B? {
/// - parameter rhs: The transformative function
/// - returns: The transformation of `lhs` using `rhs`.
public func ⇒ <A, B>(lhs: A?, rhs: ((A) -> B)?) -> B? {
if let lhs = lhs {
if let rhs = rhs {
return rhs(lhs)
}
}
return nil
if let lhs = lhs {
if let rhs = rhs {
return rhs(lhs)
}
}

return nil
}

/// Allows for a transformative function to be applied to a value.
Expand All @@ -47,7 +47,6 @@ public func ⇒ <A, B>(lhs: A?, rhs: ((A) -> B)?) -> B? {
/// - returns: The transformation of `rhs` using `lhs`.
public func ⇒ <A, B>(lhs: (A) -> B, rhs: A) -> B { return lhs(rhs) }


/// Allows for a value to be transformed by a function.
///
/// - parameter lhs: The value to apply to the function
Expand Down
Loading