Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/Engine/Processor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ extension String {
let idx = unicodeScalars.index(after: pos)
assert(idx <= end, "Input is a substring with a sub-scalar endIndex.")

if boundaryCheck && !isOnGraphemeClusterBoundary(idx) {
if boundaryCheck && idx != end && !isOnGraphemeClusterBoundary(idx) {
return nil
}

Expand All @@ -820,7 +820,7 @@ extension String {

guard cur <= end else { return nil }

if boundaryCheck && !isOnGraphemeClusterBoundary(cur) {
if boundaryCheck && cur != end && !isOnGraphemeClusterBoundary(cur) {
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions Tests/RegexTests/MatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3059,6 +3059,18 @@ extension RegexTests {
XCTAssertNotNil("tesTs".wholeMatch(of: regex))
}

func testLiteralAtSubCharacterEnd() throws {
let cafe = "cafe\u{301}"
let sub = cafe[..<cafe.unicodeScalars.index(before: cafe.endIndex)]
for regex in [#/afe/#, #/af./#] {
XCTAssertEqual(sub.firstMatch(of: regex)?.0, "afe")
}
XCTAssertNotNil(sub.firstRange(of: "afe"))

// No match for a literal ending sub-character
XCTAssertNil(cafe.firstRange(of: Regex<Substring>(verbatim: "afe")))
}

func testAutoPossessificationSkippedNodes() throws {
firstMatchTest(#"(\w* {0})a"#, input: "a", match: "a")
firstMatchTest(#"((\w* {0})){1}()a"#, input: "a", match: "a")
Expand Down
Loading