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

@@ -21,8 +21,8 @@ UTF8Decoder.test("Internal/_decodeOne") {
expectOptionalEqual(scalar.value, codePoint, "data=\(asHex(data))")
}
for i in 0..<0xd800 { ensureValid(UnicodeScalar(i)) }
for i in 0xe000...0x10ffff { ensureValid(UnicodeScalar(i)) }
for i in 0..<0xd800 { ensureValid(UnicodeScalar(i)!) }
for i in 0xe000...0x10ffff { ensureValid(UnicodeScalar(i)!) }
// Check number of valid/invalid sequences of different lengths
var validLengthCounts = [ 0, 0, 0, 0, 0 ]