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 {
438
438
guard range. location != NSNotFound else { return nil }
439
439
guard range. location >= 0 , range. length >= 0 else { return nil }
440
440
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]
442
443
guard endOffset <= bstr. utf16. count else { return nil }
443
444
444
445
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 {
2372
2372
}
2373
2373
}
2374
2374
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
+
2375
2383
#endif // FOUNDATION_FRAMEWORK
2376
2384
2377
2385
func testOOBRangeConversion( ) {
You can’t perform that action at this time.
0 commit comments