mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib/Unicode: fix encoding U+20000 and higher to UTF-16
UTF16.{leadSurrogate,trailSurrogate} were converting intermediate
results to UInt16 too soon, causing a trap on U+20000 and higher.
rdar://19156359
Swift SVN r24678
This commit is contained in:
@@ -867,7 +867,7 @@ extension UTF16 {
|
||||
/// Requires: `width(x) == 2`
|
||||
public static func leadSurrogate(x: UnicodeScalar) -> UTF16.CodeUnit {
|
||||
_precondition(width(x) == 2)
|
||||
return (UTF16.CodeUnit(x.value - 0x1_0000) >> 10) + 0xD800
|
||||
return UTF16.CodeUnit((x.value - 0x1_0000) >> 10) + 0xD800
|
||||
}
|
||||
|
||||
/// Return the low surrogate code unit of a `surrogate pair
|
||||
@@ -877,9 +877,8 @@ extension UTF16 {
|
||||
/// Requires: `width(x) == 2`
|
||||
public static func trailSurrogate(x: UnicodeScalar) -> UTF16.CodeUnit {
|
||||
_precondition(width(x) == 2)
|
||||
return (
|
||||
UTF16.CodeUnit(x.value - 0x1_0000)
|
||||
& (((1 as UTF16.CodeUnit) << 10) - 1)
|
||||
return UTF16.CodeUnit(
|
||||
(x.value - 0x1_0000) & (((1 as UInt32) << 10) - 1)
|
||||
) + 0xDC00
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user