Skip to content

Commit 0dae563

Browse files
committed
Cleanup: Attributes, Translator. Renamed: Reader. Commented on Snapshot invariant.
1 parent e41d501 commit 0dae563

File tree

9 files changed

+23
-18
lines changed

9 files changed

+23
-18
lines changed

Sources/DiffableTextKit/Models/Snapshot.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
/// on snapshots containing only formatting characters. As an example, a pattern text style
2323
/// bound to an empty value may anchor at the pattern's first placeholder character.
2424
///
25+
/// On another note, the number of attributes in the snapshot must always equal
26+
/// the number of characters in its storage string. This is usually a trivial invariant
27+
/// to maintain, but failure to maintain it will lead to unexpected behavior.
28+
///
2529
public struct Snapshot: BidirectionalCollection, RangeReplaceableCollection {
2630
@usableFromInline typealias Target = (Index) -> Bool
2731

Sources/DiffableTextKitXNumber/Models/Adapter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct NumberTextAdapter<Format: NumberTextFormat>: Equatable {
4242
// MARK: Accessors
4343
//=------------------------------------------------------------------------=
4444

45-
@inlinable var reader: Reader {
45+
@inlinable var reader: NumberTextReader {
4646
scheme.reader
4747
}
4848

Sources/DiffableTextKitXNumber/Protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extension NumberTextStyleProtocol {
6262
adapter.format
6363
}
6464

65-
@inlinable var reader: Reader {
65+
@inlinable var reader: NumberTextReader {
6666
adapter.reader
6767
}
6868

Sources/DiffableTextKitXNumber/Reader/Attributes.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ import DiffableTextKit
2626
//=------------------------------------------------------------------------=
2727

2828
@inlinable init(_ components: Components) {
29+
//=--------------------------------------=
30+
// Signs
31+
//=--------------------------------------=
32+
for sign in Sign.allCases {
33+
self.map[components.signs[sign]] = .phantom.subtracting(.virtual)
34+
}
2935
//=--------------------------------------=
3036
// Digits
3137
//=--------------------------------------=
@@ -36,12 +42,6 @@ import DiffableTextKit
3642
// Separators
3743
//=--------------------------------------=
3844
self.map[components.separators[.fraction]] = .removable
39-
//=--------------------------------------=
40-
// Signs
41-
//=--------------------------------------=
42-
for sign in Sign.allCases {
43-
self.map[components.signs[sign]] = .phantom.subtracting(.virtual)
44-
}
4545
}
4646

4747
//=------------------------------------------------------------------------=

Sources/DiffableTextKitXNumber/Reader/Reader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import DiffableTextKit
1313
// MARK: * Reader
1414
//*============================================================================*
1515

16-
public final class Reader {
16+
public final class NumberTextReader {
1717

1818
//=------------------------------------------------------------------------=
1919
// MARK: State

Sources/DiffableTextKitXNumber/Reader/Translator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
//=------------------------------------------------------------------------=
2525

2626
@inlinable init(_ local: Components) {
27+
self.insert(\.signs, from: .ascii, to: local, as: { $0 })
2728
self.insert(\.digits, from: .ascii, to: local, as: { $0 })
2829
self.insert(\.separators, from: .ascii, to: local, as: { _ in .fraction })
2930
self.insert(\.separators, from: local, to: local, as: { _ in .fraction })
30-
self.insert(\.signs, from: .ascii, to: local, as: { $0 })
3131
}
3232

3333
//=------------------------------------------------------------------------=

Sources/DiffableTextKitXNumber/Scheme+Currency.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Foundation
2222
//=------------------------------------------------------------------------=
2323

2424
@usableFromInline let id: ID
25-
@usableFromInline let reader: Reader
25+
@usableFromInline let reader: NumberTextReader
2626
@usableFromInline let preferences: Preferences
2727
@usableFromInline let adjustments: Adjustments?
2828

@@ -39,15 +39,16 @@ import Foundation
3939
formatter.currencyCode = id.code
4040
assert(formatter.numberStyle == .none)
4141
//=--------------------------------------=
42-
// Formatter: None
42+
// Formatter - None
4343
//=--------------------------------------=
4444
self.id = id
45-
self.reader = Reader(.currency(formatter))
45+
self.reader = NumberTextReader(.currency(formatter))
4646
//=--------------------------------------=
47-
// Formatter: Currency
47+
// Formatter - Currency
4848
//=--------------------------------------=
4949
formatter.numberStyle = .currency
5050
self.preferences = Preferences(formatter)
51+
5152
formatter.maximumFractionDigits = .zero
5253
self.adjustments = Adjustments(formatter, reader.components)
5354
}

Sources/DiffableTextKitXNumber/Scheme+Standard.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Foundation
2222
//=------------------------------------------------------------------------=
2323

2424
@usableFromInline let id: ID
25-
@usableFromInline let reader: Reader
25+
@usableFromInline let reader: NumberTextReader
2626

2727
//=------------------------------------------------------------------------=
2828
// MARK: Initializers
@@ -36,10 +36,10 @@ import Foundation
3636
formatter.locale = id.locale
3737
assert(formatter.numberStyle == .none)
3838
//=--------------------------------------=
39-
// Formatter: None
39+
// Formatter - None
4040
//=--------------------------------------=
4141
self.id = id
42-
self.reader = Reader(.standard(formatter))
42+
self.reader = NumberTextReader(.standard(formatter))
4343
}
4444

4545
//=------------------------------------------------------------------------=

Sources/DiffableTextKitXNumber/Scheme.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public protocol NumberTextScheme {
1919
// MARK: State
2020
//=------------------------------------------------------------------------=
2121

22-
@inlinable var reader: Reader { get }
22+
@inlinable var reader: NumberTextReader { get }
2323

2424
//=------------------------------------------------------------------------=
2525
// MARK: Autocorrect

0 commit comments

Comments
 (0)