[stdlib] location/formLocation => index/formIndex

This commit is contained in:
Dave Abrahams
2016-04-26 17:46:16 -07:00
parent debde16e2c
commit 9bee5d182f
171 changed files with 1238 additions and 1238 deletions

View File

@@ -351,13 +351,13 @@ NSStringAPIs.test("compare(_:options:range:locale:)") {
do {
let s = "abcd"
let r = s.location(after: s.startIndex)..<s.endIndex
let r = s.index(after: s.startIndex)..<s.endIndex
expectEqual(NSComparisonResult.orderedSame,
s.compare("bcd", range: r))
}
do {
let s = "абвг"
let r = s.location(after: s.startIndex)..<s.endIndex
let r = s.index(after: s.startIndex)..<s.endIndex
expectEqual(NSComparisonResult.orderedSame,
s.compare("бвг", range: r))
}
@@ -526,8 +526,8 @@ NSStringAPIs.test("enumerateLines(_:)") {
NSStringAPIs.test("enumerateLinguisticTagsIn(_:scheme:options:orthography:_:") {
let s = "Абв. Глокая куздра штеко будланула бокра и кудрячит бокрёнка. Абв."
let startIndex = s.location(s.startIndex, offsetBy: 5)
let endIndex = s.location(s.startIndex, offsetBy: 62)
let startIndex = s.index(s.startIndex, offsetBy: 5)
let endIndex = s.index(s.startIndex, offsetBy: 62)
var tags: [String] = []
var tokens: [String] = []
var sentences: [String] = []
@@ -554,8 +554,8 @@ NSStringAPIs.test("enumerateLinguisticTagsIn(_:scheme:options:orthography:_:") {
NSStringAPIs.test("enumerateSubstringsIn(_:options:_:)") {
let s = "\u{304b}\u{3099}お\u{263a}\u{fe0f}😀😊"
let startIndex = s.location(s.startIndex, offsetBy: 1)
let endIndex = s.location(s.startIndex, offsetBy: 5)
let startIndex = s.index(s.startIndex, offsetBy: 1)
let endIndex = s.index(s.startIndex, offsetBy: 5)
do {
var substrings: [String] = []
s.enumerateSubstrings(in: startIndex..<endIndex,
@@ -592,8 +592,8 @@ NSStringAPIs.test("fastestEncoding") {
NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remaining:)") {
let s = "abc абв def где gh жз zzz"
let startIndex = s.location(s.startIndex, offsetBy: 8)
let endIndex = s.location(s.startIndex, offsetBy: 22)
let startIndex = s.index(s.startIndex, offsetBy: 8)
let endIndex = s.index(s.startIndex, offsetBy: 22)
do {
// 'maxLength' is limiting.
let bufferLength = 100
@@ -611,7 +611,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
expectTrue(result)
expectEqualSequence(expectedStr, buffer)
expectEqual(11, usedLength)
expectEqual(remainingRange.lowerBound, s.location(startIndex, offsetBy: 8))
expectEqual(remainingRange.lowerBound, s.index(startIndex, offsetBy: 8))
expectEqual(remainingRange.upperBound, endIndex)
}
do {
@@ -632,7 +632,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
expectTrue(result)
expectEqualSequence(expectedStr, buffer)
expectEqual(4, usedLength)
expectEqual(remainingRange.lowerBound, s.location(startIndex, offsetBy: 4))
expectEqual(remainingRange.lowerBound, s.index(startIndex, offsetBy: 4))
expectEqual(remainingRange.upperBound, endIndex)
}
do {
@@ -672,7 +672,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain
expectTrue(result)
expectEqualSequence(expectedStr, buffer)
expectEqual(4, usedLength)
expectEqual(remainingRange.lowerBound, s.location(startIndex, offsetBy: 4))
expectEqual(remainingRange.lowerBound, s.index(startIndex, offsetBy: 4))
expectEqual(remainingRange.upperBound, endIndex)
}
}
@@ -725,7 +725,7 @@ NSStringAPIs.test("getCString(_:maxLength:encoding:)") {
NSStringAPIs.test("getLineStart(_:end:contentsEnd:forRange:)") {
let s = "Глокая куздра\nштеко будланула\nбокра и кудрячит\nбокрёнка."
let r = s.location(s.startIndex, offsetBy: 16)..<s.location(s.startIndex, offsetBy: 35)
let r = s.index(s.startIndex, offsetBy: 16)..<s.index(s.startIndex, offsetBy: 35)
do {
var outStartIndex = s.startIndex
var outLineEndIndex = s.startIndex
@@ -741,7 +741,7 @@ NSStringAPIs.test("getLineStart(_:end:contentsEnd:forRange:)") {
NSStringAPIs.test("getParagraphStart(_:end:contentsEnd:forRange:)") {
let s = "Глокая куздра\nштеко будланула\u{2028}бокра и кудрячит\u{2028}бокрёнка.\n Абв."
let r = s.location(s.startIndex, offsetBy: 16)..<s.location(s.startIndex, offsetBy: 35)
let r = s.index(s.startIndex, offsetBy: 16)..<s.index(s.startIndex, offsetBy: 35)
do {
var outStartIndex = s.startIndex
var outEndIndex = s.startIndex
@@ -870,7 +870,7 @@ NSStringAPIs.test("lengthOfBytesUsingEncoding(_:)") {
NSStringAPIs.test("lineRangeFor(_:)") {
let s = "Глокая куздра\nштеко будланула\nбокра и кудрячит\nбокрёнка."
let r = s.location(s.startIndex, offsetBy: 16)..<s.location(s.startIndex, offsetBy: 35)
let r = s.index(s.startIndex, offsetBy: 16)..<s.index(s.startIndex, offsetBy: 35)
do {
let result = s.lineRange(for: r)
expectEqual("штеко будланула\nбокра и кудрячит\n", s[result])
@@ -879,8 +879,8 @@ NSStringAPIs.test("lineRangeFor(_:)") {
NSStringAPIs.test("linguisticTagsIn(_:scheme:options:orthography:tokenRanges:)") {
let s = "Абв. Глокая куздра штеко будланула бокра и кудрячит бокрёнка. Абв."
let startIndex = s.location(s.startIndex, offsetBy: 5)
let endIndex = s.location(s.startIndex, offsetBy: 17)
let startIndex = s.index(s.startIndex, offsetBy: 5)
let endIndex = s.index(s.startIndex, offsetBy: 17)
var tokenRanges: [Range<String.Index>] = []
var tags = s.linguisticTags(in: startIndex..<endIndex,
scheme: NSLinguisticTagSchemeTokenType,
@@ -1035,7 +1035,7 @@ NSStringAPIs.test("maximumLengthOfBytesUsingEncoding(_:)") {
NSStringAPIs.test("paragraphRangeFor(_:)") {
let s = "Глокая куздра\nштеко будланула\u{2028}бокра и кудрячит\u{2028}бокрёнка.\n Абв."
let r = s.location(s.startIndex, offsetBy: 16)..<s.location(s.startIndex, offsetBy: 35)
let r = s.index(s.startIndex, offsetBy: 16)..<s.index(s.startIndex, offsetBy: 35)
do {
let result = s.paragraphRange(for: r)
expectEqual("штеко будланула\u{2028}бокра и кудрячит\u{2028}бокрёнка.\n", s[result])
@@ -1091,8 +1091,8 @@ NSStringAPIs.test("rangeOfCharacterFrom(_:options:range:)") {
do {
let s = "Глокая куздра"
let r = s.rangeOfCharacter(from: charset)!
expectEqual(s.location(s.startIndex, offsetBy: 4), r.lowerBound)
expectEqual(s.location(s.startIndex, offsetBy: 5), r.upperBound)
expectEqual(s.index(s.startIndex, offsetBy: 4), r.lowerBound)
expectEqual(s.index(s.startIndex, offsetBy: 5), r.upperBound)
}
do {
expectEmpty("клмн".rangeOfCharacter(from: charset))
@@ -1101,15 +1101,15 @@ NSStringAPIs.test("rangeOfCharacterFrom(_:options:range:)") {
let s = "абвклмнабвклмн"
let r = s.rangeOfCharacter(from: charset,
options: .backwardsSearch)!
expectEqual(s.location(s.startIndex, offsetBy: 9), r.lowerBound)
expectEqual(s.location(s.startIndex, offsetBy: 10), r.upperBound)
expectEqual(s.index(s.startIndex, offsetBy: 9), r.lowerBound)
expectEqual(s.index(s.startIndex, offsetBy: 10), r.upperBound)
}
do {
let s = "абвклмнабв"
let r = s.rangeOfCharacter(from: charset,
range: s.location(s.startIndex, offsetBy: 3)..<s.endIndex)!
expectEqual(s.location(s.startIndex, offsetBy: 7), r.lowerBound)
expectEqual(s.location(s.startIndex, offsetBy: 8), r.upperBound)
range: s.index(s.startIndex, offsetBy: 3)..<s.endIndex)!
expectEqual(s.index(s.startIndex, offsetBy: 7), r.lowerBound)
expectEqual(s.index(s.startIndex, offsetBy: 8), r.upperBound)
}
}
@@ -1140,20 +1140,20 @@ NSStringAPIs.test("rangeOfComposedCharacterSequence(at:)") {
expectEqual("\u{1F601}", s[s.rangeOfComposedCharacterSequence(
at: s.startIndex)])
expectEqual("a", s[s.rangeOfComposedCharacterSequence(
at: s.location(s.startIndex, offsetBy: 1))])
at: s.index(s.startIndex, offsetBy: 1))])
expectEqual("\u{305f}\u{3099}", s[s.rangeOfComposedCharacterSequence(
at: s.location(s.startIndex, offsetBy: 5))])
at: s.index(s.startIndex, offsetBy: 5))])
expectEqual(" ", s[s.rangeOfComposedCharacterSequence(
at: s.location(s.startIndex, offsetBy: 6))])
at: s.index(s.startIndex, offsetBy: 6))])
}
NSStringAPIs.test("rangeOfComposedCharacterSequences(for:)") {
let s = "\u{1F601}abc さ\u{3099}し\u{3099}す\u{3099}せ\u{3099}そ\u{3099}"
expectEqual("\u{1F601}a", s[s.rangeOfComposedCharacterSequences(
for: s.startIndex..<s.location(s.startIndex, offsetBy: 2))])
for: s.startIndex..<s.index(s.startIndex, offsetBy: 2))])
expectEqual("\u{3099}そ\u{3099}", s[s.rangeOfComposedCharacterSequences(
for: s.location(s.startIndex, offsetBy: 8)..<s.location(s.startIndex, offsetBy: 10))])
for: s.index(s.startIndex, offsetBy: 8)..<s.index(s.startIndex, offsetBy: 10))])
}
func toIntRange(
@@ -1469,35 +1469,35 @@ NSStringAPIs.test("replacingCharacters(in:with:)") {
expectEqual(
"\u{3099}せ\u{3099}そ\u{3099}",
s.replacingCharacters(
in: s.startIndex..<s.location(s.startIndex, offsetBy: 7), with: ""))
in: s.startIndex..<s.index(s.startIndex, offsetBy: 7), with: ""))
expectEqual(
"zzzす\u{3099}せ\u{3099}そ\u{3099}",
s.replacingCharacters(
in: s.startIndex..<s.location(s.startIndex, offsetBy: 7), with: "zzz"))
in: s.startIndex..<s.index(s.startIndex, offsetBy: 7), with: "zzz"))
expectEqual(
"\u{1F602}す\u{3099}せ\u{3099}そ\u{3099}",
s.replacingCharacters(
in: s.startIndex..<s.location(s.startIndex, offsetBy: 7), with: "\u{1F602}"))
in: s.startIndex..<s.index(s.startIndex, offsetBy: 7), with: "\u{1F602}"))
expectEqual("\u{1F601}", s.replacingCharacters(
in: s.location(after: s.startIndex)..<s.endIndex, with: ""))
in: s.index(after: s.startIndex)..<s.endIndex, with: ""))
expectEqual("\u{1F601}zzz", s.replacingCharacters(
in: s.location(after: s.startIndex)..<s.endIndex, with: "zzz"))
in: s.index(after: s.startIndex)..<s.endIndex, with: "zzz"))
expectEqual("\u{1F601}\u{1F602}", s.replacingCharacters(
in: s.location(after: s.startIndex)..<s.endIndex, with: "\u{1F602}"))
in: s.index(after: s.startIndex)..<s.endIndex, with: "\u{1F602}"))
expectEqual(
"\u{1F601}aす\u{3099}せ\u{3099}そ\u{3099}",
s.replacingCharacters(
in: s.location(s.startIndex, offsetBy: 2)..<s.location(s.startIndex, offsetBy: 7), with: ""))
in: s.index(s.startIndex, offsetBy: 2)..<s.index(s.startIndex, offsetBy: 7), with: ""))
expectEqual(
"\u{1F601}azzzす\u{3099}せ\u{3099}そ\u{3099}",
s.replacingCharacters(
in: s.location(s.startIndex, offsetBy: 2)..<s.location(s.startIndex, offsetBy: 7), with: "zzz"))
in: s.index(s.startIndex, offsetBy: 2)..<s.index(s.startIndex, offsetBy: 7), with: "zzz"))
expectEqual(
"\u{1F601}a\u{1F602}す\u{3099}せ\u{3099}そ\u{3099}",
s.replacingCharacters(
in: s.location(s.startIndex, offsetBy: 2)..<s.location(s.startIndex, offsetBy: 7),
in: s.index(s.startIndex, offsetBy: 2)..<s.index(s.startIndex, offsetBy: 7),
with: "\u{1F602}"))
}
@@ -1566,12 +1566,12 @@ NSStringAPIs.test("replacingOccurrences(of:with:options:range:)") {
s.replacingOccurrences(
of: "\u{1F601}", with: "\u{1F602}\u{1F603}",
options: NSStringCompareOptions.literalSearch,
range: s.startIndex..<s.location(s.startIndex, offsetBy: 1)))
range: s.startIndex..<s.index(s.startIndex, offsetBy: 1)))
expectEqual(s, s.replacingOccurrences(
of: "\u{1F601}", with: "\u{1F602}\u{1F603}",
options: NSStringCompareOptions.literalSearch,
range: s.location(s.startIndex, offsetBy: 1)..<s.location(s.startIndex, offsetBy: 3)))
range: s.index(s.startIndex, offsetBy: 1)..<s.index(s.startIndex, offsetBy: 3)))
}
NSStringAPIs.test("replacingPercentEscapes(using:)") {
@@ -1657,8 +1657,8 @@ NSStringAPIs.test("substring(from:)") {
expectEqual(s, s.substring(from: s.startIndex))
expectEqual("\u{3099}そ\u{3099}",
s.substring(from: s.location(s.startIndex, offsetBy: 8)))
expectEqual("", s.substring(from: s.location(s.startIndex, offsetBy: 10)))
s.substring(from: s.index(s.startIndex, offsetBy: 8)))
expectEqual("", s.substring(from: s.index(s.startIndex, offsetBy: 10)))
}
NSStringAPIs.test("substring(to:)") {
@@ -1666,8 +1666,8 @@ NSStringAPIs.test("substring(to:)") {
expectEqual("", s.substring(to: s.startIndex))
expectEqual("\u{1F601}abc さ\u{3099}し\u{3099}す\u{3099}",
s.substring(to: s.location(s.startIndex, offsetBy: 8)))
expectEqual(s, s.substring(to: s.location(s.startIndex, offsetBy: 10)))
s.substring(to: s.index(s.startIndex, offsetBy: 8)))
expectEqual(s, s.substring(to: s.index(s.startIndex, offsetBy: 10)))
}
NSStringAPIs.test("substring(with:)") {
@@ -1676,12 +1676,12 @@ NSStringAPIs.test("substring(with:)") {
expectEqual("", s.substring(with: s.startIndex..<s.startIndex))
expectEqual(
"",
s.substring(with: s.location(s.startIndex, offsetBy: 1)..<s.location(s.startIndex, offsetBy: 1)))
s.substring(with: s.index(s.startIndex, offsetBy: 1)..<s.index(s.startIndex, offsetBy: 1)))
expectEqual("", s.substring(with: s.endIndex..<s.endIndex))
expectEqual(s, s.substring(with: s.startIndex..<s.endIndex))
expectEqual(
"\u{3099}し\u{3099}す\u{3099}",
s.substring(with: s.location(s.startIndex, offsetBy: 5)..<s.location(s.startIndex, offsetBy: 8)))
s.substring(with: s.index(s.startIndex, offsetBy: 5)..<s.index(s.startIndex, offsetBy: 8)))
}
NSStringAPIs.test("localizedUppercase") {
@@ -1883,7 +1883,7 @@ NSStringAPIs.test("CompareStringsWithUnpairedSurrogates")
let acceptor = "\u{1f601}\u{1f602}\u{1f603}"
expectEqual("\u{fffd}\u{1f602}\u{fffd}",
acceptor[donor.location(donor.startIndex, offsetBy: 1)..<donor.location(donor.startIndex, offsetBy: 5)])
acceptor[donor.index(donor.startIndex, offsetBy: 1)..<donor.index(donor.startIndex, offsetBy: 5)])
}
NSStringAPIs.test("copy construction") {