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

@@ -764,6 +764,7 @@ UnicodeScalarTests.test("init") {
expectEqual("g", UnicodeScalar(UInt32(103)))
expectEqual("h", UnicodeScalar(UInt16(104)))
expectEqual("i", UnicodeScalar(UInt8(105)))
expectEqual(nil, UnicodeScalar(UInt32(0xD800)))
}
var UTF8Decoder = TestSuite("UTF8Decoder")
@@ -2357,7 +2358,7 @@ StringCookedViews.test("UTF16") {
StringCookedViews.test("UnicodeScalars") {
for test in UTF8TestsSmokeTest {
let expectedScalars = test.scalars.map { UnicodeScalar($0) }
let expectedScalars = test.scalars.map { UnicodeScalar($0)! }
let subject = NonContiguousNSString(test.scalars) as String
checkSliceableWithBidirectionalIndex(
expectedScalars, subject.unicodeScalars)
@@ -2366,7 +2367,7 @@ StringCookedViews.test("UnicodeScalars") {
forStringsWithUnpairedSurrogates {
(test: UTF16Test, subject: String) -> Void in
let expectedScalars = (test.scalarsHead + test.scalarsRepairedTail).map {
UnicodeScalar($0)
UnicodeScalar($0)!
}
checkSliceableWithBidirectionalIndex(
expectedScalars, subject.unicodeScalars)