_BString: Add index rounding methods to all views

This commit is contained in:
Karoy Lorentey committed 2023-03-20 13:12:12 -07:00
1 parent 258d22947c
commit 03d7c43c22
8 files changed
+96

No files matched your search

@@ -61,4 +61,15 @@ extension _BString: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BString {
internal func index(roundingDown i: Index) -> Index {
characterIndex(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
characterIndex(roundingUp: i)
}
}
#endif
@@ -97,4 +97,15 @@ extension _BString.UTF16View: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BString.UTF16View {
internal func index(roundingDown i: Index) -> Index {
_base.utf16Index(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
_base.utf16Index(roundingUp: i)
}
}
#endif
@@ -97,4 +97,15 @@ extension _BString.UTF8View: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BString.UTF8View {
internal func index(roundingDown i: Index) -> Index {
_base.utf8Index(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
_base.utf8Index(roundingUp: i)
}
}
#endif
@@ -101,6 +101,17 @@ extension _BString.UnicodeScalarView: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BString.UnicodeScalarView {
internal func index(roundingDown i: Index) -> Index {
_base.unicodeScalarIndex(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
_base.unicodeScalarIndex(roundingUp: i)
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BString.UnicodeScalarView: RangeReplaceableCollection {
internal init() {
@@ -169,4 +169,17 @@ extension _BSubstring.UTF16View: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BSubstring.UTF16View {
internal func index(roundingDown i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.utf16Index(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.utf16Index(roundingUp: i)
}
}
#endif
@@ -143,4 +143,17 @@ extension _BSubstring.UTF8View: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BSubstring.UTF8View {
internal func index(roundingDown i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.utf8Index(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.utf8Index(roundingUp: i)
}
}
#endif
@@ -150,6 +150,19 @@ extension _BSubstring.UnicodeScalarView: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BSubstring.UnicodeScalarView {
internal func index(roundingDown i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.unicodeScalarIndex(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.unicodeScalarIndex(roundingUp: i)
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BSubstring.UnicodeScalarView {
/// Run the closure `body` to mutate the contents of this view within `range`, then update
@@ -213,6 +213,19 @@ extension _BSubstring: BidirectionalCollection {
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BSubstring {
internal func index(roundingDown i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.characterIndex(roundingDown: i)
}
internal func index(roundingUp i: Index) -> Index {
precondition(i >= startIndex && i <= endIndex, "Index out of bounds")
return _base.characterIndex(roundingUp: i)
}
}
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension _BSubstring {
/// Run the closure `body` to mutate the contents of this view within `range`, then update