From 64a8098bf9a9da15986368358ef6a87e37f95ca5 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 13 Mar 2023 20:35:42 -0700 Subject: [PATCH] =?UTF-8?q?=5FBSubstring.UnicodeScalarView:=20Fix=20range-?= =?UTF-8?q?replacing=20mutations=20that=20don=E2=80=99t=20take=20indices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/_BSubstring+UnicodeScalarView.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/RopeModule/BString/Views/_BSubstring+UnicodeScalarView.swift b/Sources/RopeModule/BString/Views/_BSubstring+UnicodeScalarView.swift index 7a5cef78..6b28d6f8 100644 --- a/Sources/RopeModule/BString/Views/_BSubstring+UnicodeScalarView.swift +++ b/Sources/RopeModule/BString/Views/_BSubstring+UnicodeScalarView.swift @@ -257,14 +257,16 @@ extension _BSubstring.UnicodeScalarView: RangeReplaceableCollection { } internal mutating func append(_ newElement: UnicodeScalar) { - _mutateBasePreservingBounds(in: endIndex ..< endIndex) { - $0.append(newElement) + let i = endIndex + _mutateBasePreservingBounds(in: i ..< i) { + $0.insert(newElement, at: i) } } internal mutating func append>(contentsOf newElements: __owned S) { - _mutateBasePreservingBounds(in: endIndex ..< endIndex) { - $0.append(contentsOf: newElements) + let i = endIndex + _mutateBasePreservingBounds(in: i ..< i) { + $0.insert(contentsOf: newElements, at: i) } } @@ -285,7 +287,8 @@ extension _BSubstring.UnicodeScalarView: RangeReplaceableCollection { @discardableResult internal mutating func remove(at i: Index) -> UnicodeScalar { - _mutateBasePreservingBounds(in: i ..< i) { + let j = self.index(after: i) + return _mutateBasePreservingBounds(in: i ..< j) { $0.remove(at: i) } }