[stdlib] indexing model: Interval/Range merge

This is step 1; we still need to introduce ClosedRange.
This commit is contained in:
Dave Abrahams
2016-03-16 15:57:35 -07:00
parent 8c5cf9b4fc
commit f493b54e44
49 changed files with 431 additions and 633 deletions

View File

@@ -57,7 +57,7 @@ var unicodeScalarRanges: [Range<UInt32>] = [UInt32(0)...0xd7ff, 0xe000...0x10fff
var unicodeScalarCount: Int {
var count = 0
for r in unicodeScalarRanges {
count += Int(r.endIndex - r.startIndex)
count += Int(r.upperBound - r.lowerBound)
}
return count
}
@@ -65,9 +65,9 @@ var unicodeScalarCount: Int {
func nthUnicodeScalar(n: UInt32) -> UnicodeScalar {
var count: UInt32 = 0
for r in unicodeScalarRanges {
count += r.endIndex - r.startIndex
count += r.upperBound - r.lowerBound
if count > n {
return UnicodeScalar(r.endIndex - (count - n))
return UnicodeScalar(r.upperBound - (count - n))
}
}
_preconditionFailure("Index out of range")