Skip to content

Commit c48c0b0

Browse files
committed
Made PatternTextStyle's properties public variables. Made .pattern(_:) generic. Cleanup.
1 parent c6d7af5 commit c48c0b0

File tree

7 files changed

+37
-53
lines changed

7 files changed

+37
-53
lines changed

Sources/DiffableTextKitXPattern/Placeholders.swift

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// MARK: * Placeholders
1212
//*============================================================================*
1313

14-
@usableFromInline struct Placeholders: Equatable {
14+
public struct PatternTextPlaceholders: Equatable {
1515

1616
@usableFromInline typealias Predicate = (Character) -> Bool
1717

@@ -25,16 +25,16 @@
2525
// MARK: Initializers
2626
//=------------------------------------------------------------------------=
2727

28-
@inlinable init() {
28+
@inlinable public init() {
2929
self.option = .none
3030
}
3131

32-
@inlinable init(_ some: Some.Elements) {
33-
self.option = .some(Some(some))
32+
@inlinable public init(_ placeholers: (Character, (Character) -> Bool)) {
33+
self.option = .some(Some(placeholers))
3434
}
3535

36-
@inlinable init(_ many: Many.Elements) {
37-
self.option = .many(Many(many))
36+
@inlinable public init(_ placeholers: [Character: (Character) -> Bool]) {
37+
self.option = .many(Many(placeholers))
3838
}
3939

4040
//=------------------------------------------------------------------------=
@@ -63,23 +63,21 @@
6363
// MARK: + Option(s)
6464
//=----------------------------------------------------------------------------=
6565

66-
extension Placeholders {
66+
extension PatternTextPlaceholders {
6767

6868
//*========================================================================*
6969
// MARK: * Some [...]
7070
//*========================================================================*
7171

7272
@usableFromInline struct Some: Equatable {
73-
74-
@usableFromInline typealias Elements = (Character, Predicate)
75-
73+
7674
//=--------------------------------------------------------------------=
7775

78-
@usableFromInline let elements: Elements
76+
@usableFromInline let elements: (Character, Predicate)
7977

8078
//=--------------------------------------------------------------------=
8179

82-
@inlinable init( _ elements: Elements) {
80+
@inlinable init( _ elements: (Character, Predicate)) {
8381
self.elements = elements
8482
}
8583

@@ -97,16 +95,14 @@ extension Placeholders {
9795
//*========================================================================*
9896

9997
@usableFromInline struct Many: Equatable {
100-
101-
@usableFromInline typealias Elements = [Character: Predicate]
102-
98+
10399
//=--------------------------------------------------------------------=
104100

105-
@usableFromInline let elements: Elements
101+
@usableFromInline let elements: [Character: Predicate]
106102

107103
//=--------------------------------------------------------------------=
108104

109-
@inlinable init( _ elements: Elements) {
105+
@inlinable init( _ elements: [Character: Predicate]) {
110106
self.elements = elements
111107
}
112108

Sources/DiffableTextKitXPattern/Style.swift

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,35 @@ import DiffableTextKit
1616
public struct PatternTextStyle<Value>: DiffableTextStyle where Value: Equatable,
1717
Value: RangeReplaceableCollection, Value.Element == Character {
1818

19+
public typealias Placeholders = PatternTextPlaceholders
20+
1921
//=------------------------------------------------------------------------=
2022
// MARK: State
2123
//=------------------------------------------------------------------------=
2224

23-
@usableFromInline let pattern: String
24-
@usableFromInline var placeholders = Placeholders()
25-
@usableFromInline var hidden = false
25+
public var pattern: String
26+
public var placeholders: Placeholders
27+
public var hidden: Bool
2628

2729
//=------------------------------------------------------------------------=
2830
// MARK: Initializers
2931
//=------------------------------------------------------------------------=
3032

31-
@inlinable public init(_ pattern: String) { self.pattern = pattern }
33+
@inlinable public init(_ pattern: String, placeholders: Placeholders = .init(), hidden: Bool = false) {
34+
self.pattern = pattern; self.placeholders = placeholders; self.hidden = hidden
35+
}
3236

3337
//=------------------------------------------------------------------------=
3438
// MARK: Transformations
3539
//=------------------------------------------------------------------------=
3640

37-
/// Marks a single character as a placeholder.
41+
/// Marks a single character as the style's placeholder.
3842
@inlinable public func placeholders(_ character: Character,
3943
where predicate: @escaping (Character) -> Bool) -> Self {
4044
var S0 = self; S0.placeholders = .init((character, predicate)); return S0
4145
}
4246

43-
/// Marks multiple characters as placeholders.
47+
/// Marks multiple characters as the style's placeholders.
4448
@inlinable public func placeholders(_ placeholders: [Character: (Character) -> Bool]) -> Self {
4549
var S0 = self; S0.placeholders = .init(placeholders); return S0
4650
}
@@ -250,29 +254,8 @@ extension PatternTextStyle {
250254
//*============================================================================*
251255
// MARK: * Style x Init
252256
//*============================================================================*
253-
//=----------------------------------------------------------------------------=
254-
// MARK: + String
255-
//=----------------------------------------------------------------------------=
256-
257-
extension DiffableTextStyle where Self == PatternTextStyle<String> {
258-
259-
/// Creates a `PatternTextStyle` without placeholders.
260-
///
261-
/// ```
262-
/// DiffableTextField(value: $number) {
263-
/// .pattern("+## (###) ###-##-##")
264-
/// .placeholders("#") { $0.isASCII && $0.isNumber }
265-
/// }
266-
/// ```
267-
///
268-
@inlinable public static func pattern(_ pattern: String) -> Self { Self(pattern) }
269-
}
270257

271-
//=----------------------------------------------------------------------------=
272-
// MARK: + Array<Character>
273-
//=----------------------------------------------------------------------------=
274-
275-
extension DiffableTextStyle where Self == PatternTextStyle<[Character]> {
258+
extension DiffableTextStyle {
276259

277260
/// Creates a `PatternTextStyle` without placeholders.
278261
///
@@ -283,5 +266,7 @@ extension DiffableTextStyle where Self == PatternTextStyle<[Character]> {
283266
/// }
284267
/// ```
285268
///
286-
@inlinable public static func pattern(_ pattern: String) -> Self { Self(pattern) }
269+
@inlinable public static func pattern<T>(_ pattern: String) -> Self where Self == PatternTextStyle<T> {
270+
Self(pattern)
271+
}
287272
}

Sources/DiffableTextKitXUIKit/Environment+ToolbarDoneButton.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public extension View {
5757
///
5858
/// **Notes**
5959
///
60+
/// - The value is read when the view is set up.
6061
/// - The default value is `nil` (no toolbar installed).
6162
/// - The `SwiftUI/toolbar` environment value is inaccessible.
6263
///

Tests/DiffableTextKitXNumberTests/Styles/Style+Currency.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extension StyleTestsOnCurrency {
7272
//=------------------------------------------------------------------------=
7373

7474
func testDecimal() {
75-
XCTAssertCurrencies(-1.23 as Decimal)
75+
XCTAssertCurrencies(Decimal(string: "-1234567.89")!)
7676
}
7777
}
7878

@@ -106,7 +106,7 @@ extension StyleTestsOnCurrency {
106106
}
107107

108108
func testInt8() {
109-
XCTAssertCurrencies(-012 as Int8) // 9s
109+
XCTAssertCurrencies(-12_ as Int8) // 9s
110110
}
111111

112112
func testInt16() {
@@ -137,7 +137,7 @@ extension StyleTestsOnCurrency {
137137
}
138138

139139
func testUInt8() {
140-
XCTAssertCurrencies(012 as UInt8) // 9s
140+
XCTAssertCurrencies(12_ as UInt8) // 9s
141141
}
142142

143143
func testUInt16() {

Tests/DiffableTextKitXNumberTests/Styles/Style+Number.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension StyleTestsOnNumber {
4141
//=------------------------------------------------------------------------=
4242

4343
func testDecimal() {
44-
XCTAssertLocales(-1.23 as Decimal)
44+
XCTAssertLocales(Decimal(string: "-1234567.89")!)
4545
}
4646
}
4747

@@ -75,7 +75,7 @@ extension StyleTestsOnNumber {
7575
}
7676

7777
func testInt8() {
78-
XCTAssertLocales(-012 as Int8) // 9s
78+
XCTAssertLocales(-12_ as Int8) // 9s
7979
}
8080

8181
func testInt16() {
@@ -106,7 +106,7 @@ extension StyleTestsOnNumber {
106106
}
107107

108108
func testUInt8() {
109-
XCTAssertLocales(012 as UInt8) // 9s
109+
XCTAssertLocales(12_ as UInt8) // 9s
110110
}
111111

112112
func testUInt16() {

Tests/DiffableTextKitXNumberTests/Styles/Style+Percent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension StyleTestsOnPercent {
4141
//=------------------------------------------------------------------------=
4242

4343
func testDecimal() {
44-
XCTAssertLocales(-1.23 as Decimal)
44+
XCTAssertLocales(Decimal(string: "-1234567.89")!)
4545
}
4646
}
4747

Tests/DiffableTextKitXPatternTests/Placeholders.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import XCTest
1919

2020
final class PlaceholdersTests: XCTestCase {
2121

22+
typealias Placeholders = PatternTextPlaceholders
23+
2224
//=------------------------------------------------------------------------=
2325
// MARK: State
2426
//=------------------------------------------------------------------------=

0 commit comments

Comments
 (0)