Skip to content

Commit ccdde13

Browse files
committed
Cleanup. Moved numeric rounding rule to Adapter such that NumericTextStyle/format may be used without performance considerations.
1 parent 3b1c67c commit ccdde13

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

Sources/DiffableTextStylesXNumeric/Format.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ extension NumericTextFormat {
7878
try parseStrategy.parse(characters)
7979
}
8080

81+
//=------------------------------------------------------------------------=
82+
// MARK: Autocorrect
83+
//=------------------------------------------------------------------------=
84+
85+
/// The format should always round towards zero.
86+
@inlinable func autocorrect() -> Self {
87+
self.rounded(.towardZero)
88+
}
89+
8190
//=------------------------------------------------------------------------=
8291
// MARK: Transformations
8392
//=------------------------------------------------------------------------=

Sources/DiffableTextStylesXNumeric/Helpers/Adapter.swift

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,8 @@ import Foundation
2929
//=------------------------------------------------------------------------=
3030

3131
@inlinable init(_ format: Format) {
32-
self.format = format
33-
self.scheme = format.scheme()
34-
}
35-
36-
//=------------------------------------------------------------------------=
37-
// MARK: Accessors
38-
//=------------------------------------------------------------------------=
39-
40-
@inlinable var locale: Locale {
41-
format.locale
32+
self.format = format.autocorrect()
33+
self.scheme = self.format.scheme()
4234
}
4335

4436
//=------------------------------------------------------------------------=
@@ -69,18 +61,3 @@ import Foundation
6961
lhs.format == rhs.format
7062
}
7163
}
72-
73-
//=----------------------------------------------------------------------------=
74-
// MARK: + Currency
75-
//=----------------------------------------------------------------------------=
76-
77-
extension Adapter where Format: Formats.Currency {
78-
79-
//=------------------------------------------------------------------------=
80-
// MARK: Accessors
81-
//=------------------------------------------------------------------------=
82-
83-
@inlinable var currencyCode: String {
84-
format.currencyCode
85-
}
86-
}

Sources/DiffableTextStylesXNumeric/Style+Currency.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension NumericTextStyle where Format: NumericTextFormatXCurrency {
2929
//=------------------------------------------------------------------------=
3030

3131
@inlinable public var currencyCode: String {
32-
self.adapter.currencyCode
32+
format.currencyCode
3333
}
3434
}
3535

Sources/DiffableTextStylesXNumeric/Style.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct _NumericTextStyle<Format: NumericTextFormat>: DiffableTextStyle {
4444
//=------------------------------------------------------------------------=
4545

4646
@inlinable var format: Format {
47-
adapter.format.rounded(.towardZero)
47+
adapter.format
4848
}
4949

5050
@inlinable var scheme: Scheme {
@@ -60,7 +60,7 @@ public struct _NumericTextStyle<Format: NumericTextFormat>: DiffableTextStyle {
6060
//=------------------------------------------------------------------------=
6161

6262
@inlinable public var locale: Locale {
63-
adapter.locale
63+
format.locale
6464
}
6565

6666
@inlinable public func locale(_ locale: Locale) -> Self {

Sources/DiffableTextViewsXiOS/Helpers/&NSTextAlignment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension NSTextAlignment {
3131
}
3232

3333
//=------------------------------------------------------------------------=
34-
// MARK: Initializers - Helpers
34+
// MARK: Initializers - Static
3535
//=------------------------------------------------------------------------=
3636

3737
@inlinable static func adaptive(_ layout: UIUserInterfaceLayoutDirection,

0 commit comments

Comments
 (0)