Swift 6 String's init?(data: Data, encoding: String.Encoding) fails validation during encoding utf8 data to ascii and returns nil.
As proposed solution we inspect memory buffer bound to UInt8/CChar bytes, assuming they are null-terminted which allows us to produce a new string by simply copying them and interpreting as ascii.
Swift 6 String's
init?(data: Data, encoding: String.Encoding)
fails validation during encodingutf8
data toascii
and returnsnil
.As proposed solution we inspect memory buffer bound to
UInt8/CChar
bytes, assuming they are null-terminted which allows us to produce a new string by simply copying them and interpreting asascii
.