Range(NSRange,in:String) platform discrepancy

When converting from NSRange to Range, and NSRange splits a grapheme cluster, what is the expected behavior of Range init?

let text = "o\u{0301}"
let nsr = NSRange(location: 0, length: 1)
let range = Range(nsr, in: text)

From my testing, running this on macOS gives Range instance matching NSRange, and on Ubuntu gives nil.

Tried on:

Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx14.0

ubuntu-22.04
Swift version 6.0.2 (swift-6.0.2-RELEASE)
Target: x86_64-unknown-linux-gnu

Related: ¹ ²

1 Like