Skip to content

Commit e6586ac

Browse files
authored
Merge pull request #21465 from linux-on-ibm-z/s390x-unicode-scalar-fix
[stdlib] Fix Unicode.Scalar to String cast on big endian machines
2 parents cfa0050 + cdd5aa0 commit e6586ac

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

stdlib/public/core/UnicodeScalar.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ extension Unicode.Scalar {
474474
) rethrows -> Result {
475475
let encodedScalar = UTF8.encode(self)!
476476
var (codeUnits, utf8Count) = encodedScalar._bytes
477+
478+
// The first code unit is in the least significant byte of codeUnits.
479+
codeUnits = codeUnits.littleEndian
477480
return try Swift.withUnsafePointer(to: &codeUnits) {
478481
return try $0.withMemoryRebound(to: UInt8.self, capacity: 4) {
479482
return try body(UnsafeBufferPointer(start: $0, count: utf8Count))

0 commit comments

Comments
 (0)