-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNBKDoubleWidth+Text.swift
35 lines (28 loc) · 1.51 KB
/
NBKDoubleWidth+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
//=----------------------------------------------------------------------------=
// This source file is part of the Numberick open source project.
//
// Copyright (c) 2023 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
import NBKCoreKit
//*============================================================================*
// MARK: * NBK x Double Width x Text
//*============================================================================*
extension NBKDoubleWidth {
//=------------------------------------------------------------------------=
// MARK: Details x Decoding
//=------------------------------------------------------------------------=
@inlinable public init?(_ description: some StringProtocol, radix: Int) {
let decoder = NBK.IntegerDescription.Decoder<Magnitude>(radix: radix)
guard let components = decoder.decode(description) else { return nil }
self.init(sign: components.sign, magnitude: components.magnitude)
}
//=------------------------------------------------------------------------=
// MARK: Details x Encoding
//=------------------------------------------------------------------------=
@inlinable public func description(radix: Int, uppercase: Bool) -> String {
NBK.IntegerDescription.Encoder(radix: radix, uppercase: uppercase).encode(self)
}
}