-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathANKSigned+Text.swift
57 lines (47 loc) · 2.56 KB
/
ANKSigned+Text.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
//=----------------------------------------------------------------------------=
// This source file is part of the AwesomeNumbersKit open source project.
//
// Copyright (c) 2022 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
//*============================================================================*
// MARK: * ANK x Signed x Text
//*============================================================================*
extension ANKSigned {
//=------------------------------------------------------------------------=
// MARK: Details x Decode
//=------------------------------------------------------------------------=
@inlinable public init?(_ description: String) {
self.init(description, radix: 10)
}
//=------------------------------------------------------------------------=
// MARK: Details x Encode
//=------------------------------------------------------------------------=
@_transparent public var description: String {
self.description(radix: 10, uppercase: false)
}
}
//=----------------------------------------------------------------------------=
// MARK: + String
//=----------------------------------------------------------------------------=
extension String {
//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=
/// Creates a string representing the given value, in the given format.
///
/// ```
/// ┌──────────────┬───────┬─────────── → ────────────┐
/// │ integer │ radix │ uppercase │ self │
/// ├──────────────┼───────┼─────────── → ────────────┤
/// │ Int256( 123) │ 12 │ true │ "A3" │
/// │ Int256(-123) │ 16 │ false │ "-7b" │
/// └──────────────┴───────┴─────────── → ────────────┘
/// ```
///
@inlinable public init<T>(_ value: ANKSigned<T>, radix: Int = 10, uppercase: Bool = false) {
self = value.description(radix: radix, uppercase: uppercase)
}
}