File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
Sources/FoundationEssentials/AttributedString
Tests/FoundationEssentialsTests/AttributedString Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -438,7 +438,8 @@ extension Range where Bound == AttributedString.Index {
438438 guard range. location != NSNotFound else { return nil }
439439 guard range. location >= 0 , range. length >= 0 else { return nil }
440440 let endOffset = range. location + range. length
441- let bstr = string. __guts. string
441+ let bstrBounds = Range < BigString . Index > ( uncheckedBounds: ( string. startIndex. _value, string. endIndex. _value) )
442+ let bstr = string. __guts. string [ bstrBounds]
442443 guard endOffset <= bstr. utf16. count else { return nil }
443444
444445 let start = bstr. utf16. index ( bstr. startIndex, offsetBy: range. location)
Original file line number Diff line number Diff line change @@ -2372,6 +2372,14 @@ E {
23722372 }
23732373 }
23742374
2375+ func testNSRangeConversionOnSlice( ) throws {
2376+ let str = AttributedString ( " 012345 " )
2377+ let slice = str [ str. index ( str. startIndex, offsetByCharacters: 3 ) ..< str. endIndex]
2378+ let nsRange = NSRange ( location: 0 , length: 2 )
2379+ let range = try XCTUnwrap ( Range ( nsRange, in: slice) )
2380+ XCTAssertEqual ( String ( slice [ range] . characters) , " 34 " )
2381+ }
2382+
23752383#endif // FOUNDATION_FRAMEWORK
23762384
23772385 func testOOBRangeConversion( ) {
You can’t perform that action at this time.
0 commit comments