File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
stdlib/public/SDK/Foundation Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ extension String.UTF16View.Index : Strideable {
21
21
}
22
22
23
23
public func distance( to other: String . UTF16View . Index ) -> Int {
24
- return other . _offset. distance ( to: _offset)
24
+ return _offset. distance ( to: other . _offset)
25
25
}
26
26
27
27
public func advanced( by n: Int ) -> String . UTF16View . Index {
Original file line number Diff line number Diff line change @@ -323,6 +323,22 @@ StringTests.test("CompareStringsWithUnpairedSurrogates")
323
323
)
324
324
}
325
325
326
+ //[SR-1988] Ranges of String.UTF16View.Index have negative count
327
+ StringTests . test ( " String.UTF16View.Index-count " ) {
328
+ let str = " How many elements do I contain? " . utf16
329
+ let indices : Range = str. startIndex ..< str. endIndex
330
+ expectEqual ( indices. count , 31 )
331
+ expectTrue ( indices. count >= 0 )
332
+
333
+ let blank = " " . utf16
334
+ let blankindices : Range = blank. startIndex ..< blank. endIndex
335
+ expectEqual ( indices. count , 0 )
336
+
337
+ let one = " 1 " . utf16
338
+ let oneindices : Range = one. startIndex ..< one. endIndex
339
+ expectEqual ( indices. count , 1 )
340
+ }
341
+
326
342
var CStringTests = TestSuite ( " CStringTests " )
327
343
328
344
func getNullUTF8( ) -> UnsafeMutablePointer < UInt8 > ? {
You can’t perform that action at this time.
0 commit comments