Skip to content

Commit 3fcfcd6

Browse files
authored
Merge pull request #1841 from norio-nomura/fix-sr-9454
2 parents 5f20cf6 + de8eace commit 3fcfcd6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Foundation/NSStringAPI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ extension StringProtocol where Index == String.Index {
443443
/// Return an `Index` corresponding to the given offset in our UTF-16
444444
/// representation.
445445
func _index(_ utf16Index: Int) -> Index {
446-
return Index(encodedOffset: utf16Index + _substringOffset)
446+
return self.utf16.index(self.utf16.startIndex, offsetBy: utf16Index)
447447
}
448448

449449
@inlinable

TestFoundation/TestNSString.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class TestNSString: LoopbackServerTest {
9494
("test_substringWithRange", test_substringWithRange),
9595
("test_substringFromCFString", test_substringFromCFString),
9696
("test_createCopy", test_createCopy),
97-
("test_commonPrefix", test_commonPrefix)
97+
("test_commonPrefix", test_commonPrefix),
98+
("test_lineRangeFor", test_lineRangeFor)
9899
]
99100
}
100101

@@ -1330,6 +1331,18 @@ class TestNSString: LoopbackServerTest {
13301331
XCTAssertEqual("m\u{E4}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.caseInsensitive, .literal]), "mädchen")
13311332
XCTAssertEqual("ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.caseInsensitive, .literal]), "m")
13321333
}
1334+
1335+
func test_lineRangeFor() {
1336+
// column 1 2 3 4 5 6 7 8 9 10 11
1337+
// line 1 L I N E 1 _ 6 7 あ \n
1338+
// line 2 L I N E 2 _ 7 8 9 0 \n
1339+
// line 3 L I N E 3 _ 8 9 0 1 \n
1340+
let string = "LINE1_67あ\nLINE2_7890\nLINE3_8901\n"
1341+
let rangeOfFirstLine = string.lineRange(for: string.startIndex..<string.startIndex)
1342+
XCTAssertEqual(string.distance(from: rangeOfFirstLine.lowerBound, to: rangeOfFirstLine.upperBound), 10)
1343+
let firstLine = string[rangeOfFirstLine]
1344+
XCTAssertEqual(firstLine, "LINE1_67あ\n")
1345+
}
13331346
}
13341347

13351348
func test_reflection() {

0 commit comments

Comments
 (0)