-
Notifications
You must be signed in to change notification settings - Fork 104
/
IntBox.swift
62 lines (51 loc) · 1.51 KB
/
IntBox.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
//
// IntBox.swift
// XMLCoder
//
// Created by Vincent Esche on 12/17/18.
//
import Foundation
struct IntBox: Equatable {
typealias Unboxed = Int64
let unboxed: Unboxed
init<Integer: SignedInteger>(_ unboxed: Integer) {
self.unboxed = Unboxed(unboxed)
}
init?(xmlString: String) {
guard let unboxed = Unboxed(xmlString) else {
return nil
}
self.init(unboxed)
}
func unbox<Integer: BinaryInteger>() -> Integer? {
return Integer(exactly: self.unboxed)
}
}
extension IntBox: Box {
var isNull: Bool {
return false
}
/// # Lexical representation
/// Integer has a lexical representation consisting of a finite-length sequence of
/// decimal digits with an optional leading sign. If the sign is omitted, `"+"` is assumed.
/// For example: `-1`, `0`, `12678967543233`, `+100000`.
///
/// # Canonical representation
/// The canonical representation for integer is defined by prohibiting certain
/// options from the Lexical representation. Specifically, the preceding optional
/// `"+"` sign is prohibited and leading zeroes are prohibited.
///
/// ---
///
/// [Schema definition](https://www.w3.org/TR/xmlschema-2/#integer)
func xmlString() -> String? {
return self.unboxed.description
}
}
extension IntBox: SimpleBox {
}
extension IntBox: CustomStringConvertible {
var description: String {
return self.unboxed.description
}
}