forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnkeyedBox.swift
63 lines (51 loc) · 1.19 KB
/
UnkeyedBox.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// UnkeyedBox.swift
// XMLCoderPackageDescription
//
// Created by Vincent Esche on 11/20/18.
//
// Minimalist implementation of an order-preserving unkeyed box:
struct UnkeyedBox {
typealias Element = Box
typealias Unboxed = [Element]
private(set) var unboxed: Unboxed
var count: Int {
return unboxed.count
}
subscript(index: Int) -> Element {
get {
return unboxed[index]
}
set {
unboxed[index] = newValue
}
}
init(_ unboxed: Unboxed = []) {
self.unboxed = unboxed
}
mutating func append(_ newElement: Element) {
unboxed.append(newElement)
}
mutating func insert(_ newElement: Element, at index: Int) {
unboxed.insert(newElement, at: index)
}
}
extension UnkeyedBox: Box {
var isNull: Bool {
return false
}
func xmlString() -> String? {
return nil
}
}
extension UnkeyedBox: Sequence {
typealias Iterator = Unboxed.Iterator
func makeIterator() -> Iterator {
return unboxed.makeIterator()
}
}
extension UnkeyedBox: CustomStringConvertible {
var description: String {
return "\(unboxed)"
}
}