-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: break up into multiple files
This commit also introduces a new XMLDeserialization type that hopefully will make it easier to implement deserialization for custom types.
- Loading branch information
1 parent
4d6f845
commit 1e31af3
Showing
12 changed files
with
649 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// XMLDeserializationError.swift | ||
// SWXMLHash | ||
// | ||
// Copyright (c) 2016 Maciek Grzybowskio, 2022 David Mohundro | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Bool: XMLDeserialization, XMLElementDeserializable { | ||
// swiftlint:disable line_length | ||
/** | ||
Attempts to deserialize XML element content to a Bool. This uses NSString's 'boolValue' | ||
described [here](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instp/NSString/boolValue) | ||
|
||
- parameters: | ||
- element: the XMLElement to be deserialized | ||
- throws: an XMLDeserializationError.typeConversionFailed if the element cannot be deserialized | ||
- returns: the deserialized Bool value | ||
*/ | ||
public static func deserialize(_ element: XMLElement) throws -> Bool { | ||
let value = Bool(NSString(string: try element.nonEmptyTextOrThrow()).boolValue) | ||
return value | ||
} | ||
|
||
/** | ||
Attempts to deserialize XML attribute content to a Bool. This uses NSString's 'boolValue' | ||
described [here](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instp/NSString/boolValue) | ||
|
||
- parameter attribute: The XMLAttribute to be deserialized | ||
- throws: an XMLDeserializationError.attributeDeserializationFailed if the attribute cannot be | ||
deserialized | ||
- returns: the deserialized Bool value | ||
*/ | ||
public static func deserialize(_ attribute: XMLAttribute) throws -> Bool { | ||
let value = Bool(NSString(string: attribute.text).boolValue) | ||
return value | ||
} | ||
// swiftlint:enable line_length | ||
|
||
public func validate() {} | ||
} |
Oops, something went wrong.