Ben, while I'm broadly sympathetic to making CChar work more widely, if I recall correctly this was a rather complex discussion topic you're raising again. Besides the unprecedented name (Unsigned is never spelled out at the moment), I wonder if all the other salient issues involved are best left for a wider discussion than is possible here, especially since the pitch and proposal have been limited to two properties.<br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 27, 2016 at 07:33 Ben Rimmington via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 25 Jul 2016, at 15:27, Ben Rimmington wrote:<br>
><br>
> <<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md" rel="noreferrer" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md</a>><br>
><br>
> My suggestion for SE-0134 is to use the `utf8CString` name, overloading for CSignedChar and CUnsignedChar:<br>
><br>
> <<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/CString.swift" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/stdlib/public/core/CString.swift</a>><br>
><br>
> extension String {<br>
> - init(cString: UnsafePointer<CChar>)<br>
> - init(cString: UnsafePointer<UInt8>)<br>
> - init?(validatingUTF8 cString: UnsafePointer<CChar>)<br>
><br>
> + init(utf8CString: UnsafePointer<CSignedChar>)<br>
> + init(utf8CString: UnsafePointer<CUnsignedChar>)<br>
> + init?(validatingUTF8CString: UnsafePointer<CSignedChar>)<br>
> + init?(validatingUTF8CString: UnsafePointer<CUnsignedChar>)<br>
> }<br>
><br>
> The properties would change to methods, overloaded by return type:<br>
><br>
> <<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/StringUTF8.swift" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/stdlib/public/core/StringUTF8.swift</a>><br>
><br>
> extension String {<br>
> - var nulTerminatedUTF8CString: ContiguousArray<CChar><br>
> - var nulTerminatedUTF8: ContiguousArray<UTF8.CodeUnit><br>
><br>
> + func utf8CString() -> ContiguousArray<CSignedChar><br>
> + func utf8CString() -> ContiguousArray<CUnsignedChar><br>
> }<br>
><br>
> ## NOTES ##<br>
><br>
> UTF8.CodeUnit is defined as UInt8, and CChar is currently defined as Int8:<br>
><br>
> <<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/CTypes.swift" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/stdlib/public/core/CTypes.swift</a>><br>
><br>
> /// The C 'char' type.<br>
> ///<br>
> /// This will be the same as either `CSignedChar` (in the common<br>
> /// case) or `CUnsignedChar`, depending on the platform.<br>
> public typealias CChar = Int8<br>
><br>
> /// The C 'signed char' type.<br>
> public typealias CSignedChar = Int8<br>
><br>
> /// The C 'unsigned char' type.<br>
> public typealias CUnsignedChar = UInt8<br>
><br>
> There's an abandoned proposal to update CChar:<br>
><br>
> <<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/7925/focus=8158" rel="noreferrer" target="_blank">http://thread.gmane.org/gmane.comp.lang.swift.evolution/7925/focus=8158</a>><br>
><br>
> <<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/8419" rel="noreferrer" target="_blank">http://thread.gmane.org/gmane.comp.lang.swift.evolution/8419</a>><br>
><br>
> String.init(cString: UnsafePointer<UInt8>) and nulTerminatedUTF8CString were added by SE-0107:<br>
><br>
> <<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#cstring-conversion" rel="noreferrer" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#cstring-conversion</a>><br>
><br>
> <<a href="https://github.com/apple/swift/commit/c7aa8284c905a73959ad69255cb56c38db80d039" rel="noreferrer" target="_blank">https://github.com/apple/swift/commit/c7aa8284c905a73959ad69255cb56c38db80d039</a>><br>
><br>
> Foundation.NSString uses the `utf8String` name instead:<br>
><br>
> <<a href="https://developer.apple.com/reference/foundation/nsstring/1412128-init" rel="noreferrer" target="_blank">https://developer.apple.com/reference/foundation/nsstring/1412128-init</a>><br>
><br>
> <<a href="https://developer.apple.com/reference/foundation/nsstring/1411189-utf8string" rel="noreferrer" target="_blank">https://developer.apple.com/reference/foundation/nsstring/1411189-utf8string</a>><br>
<br>
<<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md" rel="noreferrer" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md</a>><br>
<br>
There's another method for SE-0134 which could be renamed or removed:<br>
<br>
<<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/LifetimeManager.swift" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/stdlib/public/core/LifetimeManager.swift</a>><br>
<br>
extension String {<br>
- func withCString<Result>(<br>
- _ body: @noescape (UnsafePointer<Int8>) throws -> Result<br>
- ) rethrows -> Result<br>
<br>
+ func withUTF8CString<Result>(<br>
+ _ body: @noescape (UnsafePointer<CSignedChar>) throws -> Result<br>
+ ) rethrows -> Result<br>
<br>
+ func withUTF8CString<Result>(<br>
+ _ body: @noescape (UnsafePointer<CUnsignedChar>) throws -> Result<br>
+ ) rethrows -> Result<br>
}<br>
<br>
The overloads (CSignedChar and CUnsignedChar) are needed if CChar will become UInt8 on some platforms.<br>
<br>
-- Ben<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>