Change unicodescalar to failable

We were using a precondition which crashes the program when invalid input is
provided. We want to provide a way to gracefully check and handle invalid input
or shutdown the program if necessary.

SR-1930
This commit is contained in:
Xin Tong
2016-07-21 10:07:06 -07:00
parent 035823591a
commit bbf86865d6
18 changed files with 133 additions and 94 deletions

View File

@@ -60,7 +60,7 @@ func nthUnicodeScalar(_ n: UInt32) -> UnicodeScalar {
for r in unicodeScalarRanges {
count += r.upperBound - r.lowerBound
if count > n {
return UnicodeScalar(r.upperBound - (count - n))
return UnicodeScalar(r.upperBound - (count - n))!
}
}
_preconditionFailure("Index out of range")