stdlib/String: if we can not get a contiguous data buffer out of NSString,

don't call into CoreFoundation to perform UTF-8 transcoding.  CoreFoundation
can replace ill-formed sequences with a single byte, which is not good enough
to implement U+FFFD insertion.  Instead, use the same transcoding routine as
for contiguous buffer.

Pulled out the transcoding routine into a generic function that should be
specialized and simplified for the case when input is UnsafeArray; we should
not be losing efficiency here.

Fixes <rdar://problem/17297055> [unicode] println crashes when given string
with unpaired surrogate



Swift SVN r19157
This commit is contained in:
Dmitri Hrybenko
2014-06-25 13:24:15 +00:00
parent 90f578f047
commit 6bb6e1b0b4
8 changed files with 219 additions and 164 deletions

View File

@@ -106,7 +106,7 @@ extension String {
case .EmptyInput:
return .None
case .Error:
_fatalError("unpaired surrogates are ill-formed in UTF-16")
return UnicodeScalar(0xfffd)
}
}
var _decoder: UTF16 = UTF16()