Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor .sortedKeys #11

Closed
wants to merge 11 commits into from
5 changes: 5 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--indent 4
--indentcase false
--linebreaks lf
--stripunusedargs closure-only
--trimwhitespace nonblank-lines
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "XMLCoder",
targets: ["XMLCoder"]),
targets: ["XMLCoder"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -20,9 +21,11 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "XMLCoder",
dependencies: []),
dependencies: []
),
.testTarget(
name: "XMLCoderTests",
dependencies: ["XMLCoder"]),
dependencies: ["XMLCoder"]
),
]
)
2 changes: 1 addition & 1 deletion Sample XML/RJI/RJI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct RSS: Decodable {
var channel: Channel

enum CodingKeys: String, CodingKey {
case channel = "channel"
case channel

case dc = "xmlns:dc"
case sy = "xmlns:sy"
Expand Down
6 changes: 2 additions & 4 deletions Sources/XMLCoder/Decoder/DecodingErrorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal extension DecodingError {
let description = "Expected to decode \(expectation) but found \(_typeDescription(of: reality)) instead."
return .typeMismatch(expectation, Context(codingPath: path, debugDescription: description))
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like trailing whitespaces on a blank line, was this committed by mistake or added by SwiftFormat? In either case it would be great to avoid these

/// Returns a description of the type of `value` appropriate for an error message.
///
/// - parameter value: The value whose type to describe.
Expand All @@ -38,12 +38,10 @@ internal extension DecodingError {
return "a string/data"
} else if value is [Any] {
return "an array"
} else if value is [String : Any] {
} else if value is [String: Any] {
return "a dictionary"
} else {
return "\(type(of: value))"
}
}
}


241 changes: 126 additions & 115 deletions Sources/XMLCoder/Decoder/XMLDecoder.swift

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions Sources/XMLCoder/Decoder/XMLDecodingStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,33 @@ import Foundation

internal struct _XMLDecodingStorage {
// MARK: Properties

/// The container stack.
/// Elements may be any one of the XML types (String, [String : Any]).
private(set) internal var containers: [Any] = []

internal private(set) var containers: [Any] = []
// MARK: - Initialization

/// Initializes `self` with no containers.
internal init() {}

// MARK: - Modifying the Stack

internal var count: Int {
return self.containers.count
return containers.count
}

internal var topContainer: Any {
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.last!
precondition(!containers.isEmpty, "Empty container stack.")
return containers.last!
}

internal mutating func push(container: Any) {
self.containers.append(container)
containers.append(container)
}

internal mutating func popContainer() {
precondition(!self.containers.isEmpty, "Empty container stack.")
self.containers.removeLast()
precondition(!containers.isEmpty, "Empty container stack.")
containers.removeLast()
}
}

138 changes: 69 additions & 69 deletions Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift

Large diffs are not rendered by default.

218 changes: 109 additions & 109 deletions Sources/XMLCoder/Decoder/XMLUnkeyedDecodingContainer.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sources/XMLCoder/Encoder/EncodingErrorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal extension EncodingError {
/// - parameter value: The value that was invalid to encode.
/// - parameter path: The path of `CodingKey`s taken to encode this value.
/// - returns: An `EncodingError` with the appropriate path and debug description.
internal static func _invalidFloatingPointValue<T : FloatingPoint>(_ value: T, at codingPath: [CodingKey]) -> EncodingError {
internal static func _invalidFloatingPointValue<T: FloatingPoint>(_ value: T, at codingPath: [CodingKey]) -> EncodingError {
let valueDescription: String
if value == T.infinity {
valueDescription = "\(T.self).infinity"
Expand Down
Loading