Merge pull request #243 from ABridoux/bugfix/241-missing-xml-values
[#241] Missing xml values
This commit is contained in:
commit
c68c14b9a8
|
@ -14,12 +14,38 @@ extension ExplorerXML {
|
|||
try _add(value: .explorerValue(value), at: Slice(path))
|
||||
}
|
||||
|
||||
/// Add the given `AEXMLElement` value rather than an `ExplorerValue`
|
||||
public mutating func add(_ element: Element, at path: Path) throws {
|
||||
if referenceIsShared() { self = copy() }
|
||||
try _add(value: .explorerXML(ExplorerXML(element: element)), at: Slice(path))
|
||||
}
|
||||
|
||||
/// Add the given `ExplorerXML` value rather than an `ExplorerValue`
|
||||
public mutating func add(_ explorer: ExplorerXML, at path: Path) throws {
|
||||
if referenceIsShared() { self = copy() }
|
||||
try _add(value: .explorerXML(explorer), at: Slice(path))
|
||||
}
|
||||
|
||||
public func adding(_ value: ExplorerValue, at path: Path) throws -> ExplorerXML {
|
||||
var copy = self.copy()
|
||||
try copy.add(value, at: path)
|
||||
return copy
|
||||
}
|
||||
|
||||
/// Add the given `AEXMLElement` value rather than an `ExplorerValue`
|
||||
public func adding(_ element: Element, at path: Path) throws -> ExplorerXML {
|
||||
var copy = self.copy()
|
||||
try copy.add(element, at: path)
|
||||
return copy
|
||||
}
|
||||
|
||||
/// Add the given `ExplorerXML` value rather than an `ExplorerValue`
|
||||
public func adding(_ explorerXML: ExplorerXML, at path: Path) throws -> ExplorerXML {
|
||||
var copy = self.copy()
|
||||
try copy.add(explorerXML, at: path)
|
||||
return copy
|
||||
}
|
||||
|
||||
// MARK: General function
|
||||
|
||||
/// Return the value if it should be added to the parent
|
||||
|
|
|
@ -16,21 +16,33 @@ extension ExplorerXML {
|
|||
try _set(path: Slice(path), to: .explorerValue(newValue))
|
||||
}
|
||||
|
||||
/// Set the path to the given `AEXMLElement` value rather than an `ExplorerValue`
|
||||
public mutating func set(_ path: Path, to element: Element) throws {
|
||||
try _set(path: Slice(path), to: .explorerXML(ExplorerXML(element: element)))
|
||||
}
|
||||
|
||||
/// Set the path to the given `ExplorerXML` value rather than an `ExplorerValue`
|
||||
public mutating func set(_ path: Path, to explorer: ExplorerXML) throws {
|
||||
try _set(path: Slice(path), to: .explorerXML(explorer))
|
||||
}
|
||||
|
||||
public func setting(_ path: Path, to newValue: ExplorerValue) throws -> ExplorerXML {
|
||||
var modified = copy()
|
||||
try modified.set(path, to: newValue)
|
||||
return modified
|
||||
}
|
||||
|
||||
/// Set the path to the given AEXMLElement rather than an `ExplorerValue`
|
||||
public mutating func set(_ path: Path, to newElement: Element) throws {
|
||||
try _set(path: Slice(path), to: .xmlElement(newElement))
|
||||
/// Set the path to the given `AEXMLElement` value rather than an `ExplorerValue`
|
||||
public func setting(_ path: Path, to element: Element) throws -> ExplorerXML {
|
||||
var modified = copy()
|
||||
try modified.set(path, to: element)
|
||||
return modified
|
||||
}
|
||||
|
||||
/// Set the path to the given AEXMLElement rather than an `ExplorerValue`
|
||||
public func setting(_ path: Path, to newElement: Element) throws -> ExplorerXML {
|
||||
/// Set the path to the given `ExplorerXML` value rather than an `ExplorerValue`
|
||||
public func setting(_ path: Path, to explorer: ExplorerXML) throws -> ExplorerXML {
|
||||
var modified = copy()
|
||||
try modified.set(path, to: newElement)
|
||||
try modified.set(path, to: explorer)
|
||||
return modified
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public struct ExplorerXML: PathExplorer {
|
|||
public var int: Int? { element.int }
|
||||
public var double: Double? { element.double }
|
||||
|
||||
@available(*, deprecated)
|
||||
@available(*, deprecated, renamed: "double")
|
||||
public var real: Double? { element.double }
|
||||
|
||||
/// Always `nil` on XML
|
||||
|
@ -259,7 +259,7 @@ extension ExplorerXML {
|
|||
func set(value: ValueSetter) {
|
||||
switch value {
|
||||
case .explorerValue(let value): set(newValue: value)
|
||||
case .xmlElement(let element): set(newElement: element)
|
||||
case .explorerXML(let explorer): set(newElement: explorer.element)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ extension ExplorerXML {
|
|||
/// Wrapper to more easily handle setting an ExplorerValue or Element
|
||||
enum ValueSetter {
|
||||
case explorerValue(ExplorerValue)
|
||||
case xmlElement(Element)
|
||||
case explorerXML(ExplorerXML)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,9 @@ public struct CodablePathExplorer<Format: CodableFormat>: PathExplorer {
|
|||
public var string: String? { value.string }
|
||||
public var bool: Bool? { value.bool }
|
||||
public var int: Int? { value.int }
|
||||
@available(*, deprecated, renamed: "double")
|
||||
public var real: Double? { value.real }
|
||||
public var double: Double? { value.real }
|
||||
public var data: Data? { value.data }
|
||||
public func array<T>(of type: T.Type) throws -> [T] where T: ExplorerValueCreatable { try value.array(of: type) }
|
||||
public func dictionary<T>(of type: T.Type) throws -> [String: T] where T: ExplorerValueCreatable { try value.dictionary(of: type) }
|
||||
|
|
|
@ -31,6 +31,9 @@ where
|
|||
/// Non `nil` if the key is of the `Double` type
|
||||
var real: Double? { get }
|
||||
|
||||
/// Non `nil` if the key is of the `Double` type
|
||||
var double: Double? { get }
|
||||
|
||||
/// Non `nil` if the key is of the `Data` type
|
||||
var data: Data? { get }
|
||||
|
||||
|
|
Loading…
Reference in New Issue