-
Notifications
You must be signed in to change notification settings - Fork 104
/
UIntBox.swift
63 lines (53 loc) · 1.69 KB
/
UIntBox.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
//
// UIntBox.swift
// XMLCoder
//
// Created by Vincent Esche on 12/17/18.
//
import Foundation
struct UIntBox: Equatable {
typealias Unboxed = UInt64
let unboxed: Unboxed
init<Integer: UnsignedInteger>(_ 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: unboxed)
}
}
extension UIntBox: Box {
var isNull: Bool {
return false
}
/// # Lexical representation
/// Unsigned integer has a lexical representation consisting of an optional
/// sign followed by a finite-length sequence of decimal digits.
/// If the sign is omitted, the positive sign (`"+"`) is assumed.
/// If the sign is present, it must be `"+"` except for lexical forms denoting zero,
/// which may be preceded by a positive (`"+"`) or a negative (`"-"`) sign.
/// For example: `1`, `0`, `12678967543233`, `+100000`.
///
/// # Canonical representation
/// The canonical representation for nonNegativeInteger is defined by prohibiting
/// certain options from the Lexical representation. Specifically,
/// the the optional `"+"` sign is prohibited and leading zeroes are prohibited.
///
/// ---
///
/// [Schema definition](https://www.w3.org/TR/xmlschema-2/#nonNegativeInteger)
func xmlString() -> String? {
return unboxed.description
}
}
extension UIntBox: SimpleBox {}
extension UIntBox: CustomStringConvertible {
var description: String {
return unboxed.description
}
}