Skip to content

Commit b94d36e

Browse files
committed
Cleanup.
1 parent 567a878 commit b94d36e

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

Sources/DiffableTextKit/Helpers/Carets.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
// MARK: * Carets
1212
//*============================================================================*
1313

14-
/// A lower and upper caret represented by a lower and upper bound.
14+
/// Up to two carets represented by a lower and upper bound.
1515
///
16-
/// It differs from a normal range in that equal bounds represent a single upper caret,
17-
/// rather than two carets at a shared location, which is observable by methods such
18-
/// as map(lower:upper:).
16+
/// When its bounds are equal, it represents a single upper caret.
17+
/// This distinction matters to transformations such as map(lower:upper:).
1918
///
2019
@usableFromInline struct Carets<Bound: Comparable>: Equatable {
2120

Sources/DiffableTextKit/Helpers/Index.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// MARK: * Index
1212
//*========================================================================*
1313

14+
/// A character encoded index and offset.
1415
public struct Index: Comparable {
1516

1617
//=--------------------------------------------------------------------=
@@ -23,11 +24,27 @@ public struct Index: Comparable {
2324
//=--------------------------------------------------------------------=
2425
// MARK: Initializers
2526
//=--------------------------------------------------------------------=
26-
27+
28+
/// Creates an instance describing a character's location.
29+
///
30+
/// - Parameters:
31+
/// - character: The character encoded index.
32+
/// - attribute: The character encoded offset.
33+
///
2734
@inlinable init(_ character: String.Index, _ attribute: Int) {
2835
self.character = character
2936
self.attribute = attribute
3037
}
38+
39+
/// Creates an instance describing a character's location.
40+
///
41+
/// - Parameters:
42+
/// - character: The character encoded index.
43+
/// - characters: The collection of characters that contains the index.
44+
///
45+
@inlinable init(_ character: String.Index, in characters: String) {
46+
self.init(character, characters[..<character].count)
47+
}
3148

3249
//=--------------------------------------------------------------------=
3350
// MARK: Comparisons

Sources/DiffableTextKit/Models/Offset.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ extension Character: Offset {
3535
//=------------------------------------------------------------------------=
3636

3737
@inlinable public static func index(at position: Self.Position, in characters: String) -> Index {
38-
let character = characters.index(characters.startIndex, offsetBy: position.offset)
39-
return Index(character, position.offset)
38+
Index(characters.index(characters.startIndex, offsetBy: position.offset), position.offset)
4039
}
4140

4241
@inlinable public static func position(at index: Index, in characters: String) -> Self.Position {
@@ -55,8 +54,7 @@ extension UTF16: Offset {
5554
//=------------------------------------------------------------------------=
5655

5756
@inlinable public static func index(at position: Self.Position, in characters: String) -> Index {
58-
let character = String.Index(utf16Offset: position.offset, in: characters)
59-
return Index(character, characters[..<character].count)
57+
Index(String.Index(utf16Offset: position.offset, in: characters), in: characters)
6058
}
6159

6260
@inlinable public static func position(at index: Index, in characters: String) -> Self.Position {

0 commit comments

Comments
 (0)