Create String from UTF-8 data regardless of sign type

Originator:robnapier
Number:rdar://21631197 Date Originated:01-Jul-2015 09:43 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 2b2
Classification:Enhancement Reproducible:Not Applicable
 
It should be simple to create a String from UTF-8 data regardless of the specific type. Currently a [UInt8] (unsigned) cannot be simply converted to String because String(UTF8String:) requires an UnsafePointer<Int8> (signed).

String(UTF8String:) should be modified to accept void* (since UnsafePointer<Void> accept anything). Alternately (or in addition), UnsafePointer<UInt8> and UnsafePointer<Int8> should be implicitly exchangeable to help bridge to their wildly inconsistent use in C (particularly regarding char* vs unsigned char*).

In addition to String(UTF8String: UnsafePointer<UInt8>) working correctly, String(UTF8String: [UInt8]) should work as well. The array should not require a trailing \0 (like in initWithData:encoding). (A similar name, such as String(UTF8Bytes:) would make sense as well.)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!