Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #884 from matrix-org/langleyd/fix_double_space_ind…
Browse files Browse the repository at this point in the history
…ex_issue

Remove trailingTrimmed from withNBSP
  • Loading branch information
langleyd authored Nov 21, 2023
2 parents 89282f7 + 397b98c commit 675502e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,7 @@ private struct StringDiff {
private extension String {
/// Converts all whitespaces to NBSP to avoid diffs caused by HTML translations.
var withNBSP: String {
String(map { $0.isWhitespace ? Character.nbsp : $0 }).trailingTrimmed
}

var trailingTrimmed: String {
var view = self[...]

while view.last?.isWhitespace == true || view.last?.isNewline == true {
view = view.dropLast()
}

return String(view)
String(map { $0.isWhitespace ? Character.nbsp : $0 })
}

/// Computes the diff from provided string to self. Outputs UTF16 locations and lengths.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ final class StringDifferTests: XCTestCase {
XCTAssertEqual(try StringDiffer.replacement(from: " \u{00A0} text", to: " \u{00A0} test"),
.init(location: 5, length: 1, text: "s"))
}

func testDoubleSpaceDotConversion() throws {
XCTAssertEqual(try StringDiffer.replacement(from: "a ", to: "a."),
.init(location: 1, length: 2, text: "."))
}
}

private extension CharacterSet {
Expand Down

0 comments on commit 675502e

Please sign in to comment.