Skip to content

Commit

Permalink
Merge pull request CoreOffice#48 from jsbean/transform-precondition
Browse files Browse the repository at this point in the history
Transform precondition to where clause in switch statement
  • Loading branch information
jsbean committed Sep 30, 2019
2 parents 2e40e6a + 800a26a commit e95cb2b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 10 deletions.
2 changes: 0 additions & 2 deletions Sources/XMLCoder/Decoder/XMLDecoder.swift
Expand Up @@ -349,8 +349,6 @@ open class XMLDecoder {
trimValueWhitespaces: trimValueWhitespaces
)

print("decoder.decode(\(type), from: \(data), top level: \(topLevel)")

let decoder = XMLDecoderImplementation(
referencing: topLevel,
options: options,
Expand Down
6 changes: 1 addition & 5 deletions Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift
Expand Up @@ -101,8 +101,7 @@ class XMLDecoderImplementation: Decoder {
attributes: KeyedStorage()
))
))
case let containsEmpty as SingleKeyedBox:
precondition(containsEmpty.element is NullBox)
case let containsEmpty as SingleKeyedBox where containsEmpty.element is NullBox:
return KeyedDecodingContainer(XMLKeyedDecodingContainer<Key>(
referencing: self, wrapping: SharedBox(KeyedBox(
elements: KeyedStorage([("value", StringBox(""))]), attributes: KeyedStorage()
Expand Down Expand Up @@ -444,10 +443,7 @@ extension XMLDecoderImplementation {
storage.popContainer()
}

print("type: \(type), box: \(box)")

do {
print("try decoding in init")
decoded = try type.init(from: self)
} catch {
guard case DecodingError.valueNotFound = error,
Expand Down
3 changes: 0 additions & 3 deletions Sources/XMLCoder/Decoder/XMLKeyedDecodingContainer.swift
Expand Up @@ -324,14 +324,11 @@ extension XMLKeyedDecodingContainer {
box = anyBox
}

print(box)

let value: T?
if !(type is AnySequence.Type), let unkeyedBox = box as? UnkeyedBox,
let first = unkeyedBox.first {
// Handle case where we have held onto a `SingleKeyedBox`
if let singleKeyed = first as? SingleKeyedBox {
print("single keyed here?: \(singleKeyed.element)")
if singleKeyed.element.isNull {
value = try decoder.unbox(singleKeyed)
} else {
Expand Down

0 comments on commit e95cb2b

Please sign in to comment.