<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I'm +1 on the proposal.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 27 juil. 2016 à 07:08:44, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class="">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 class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Jul 27, 2016 at 07:33 Ben Rimmington via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
&gt; On 25 Jul 2016, at 15:27, Ben Rimmington wrote:<br class="">
&gt;<br class="">
&gt; &lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md</a>&gt;<br class="">
&gt;<br class="">
&gt; My suggestion for SE-0134 is to use the `utf8CString` name, overloading for CSignedChar and CUnsignedChar:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/CString.swift" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/CString.swift</a>&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;extension String {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;- init(cString: UnsafePointer&lt;CChar&gt;)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;- init(cString: UnsafePointer&lt;UInt8&gt;)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;- init?(validatingUTF8 cString: UnsafePointer&lt;CChar&gt;)<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;+ init(utf8CString: UnsafePointer&lt;CSignedChar&gt;)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;+ init(utf8CString: UnsafePointer&lt;CUnsignedChar&gt;)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;+ init?(validatingUTF8CString: UnsafePointer&lt;CSignedChar&gt;)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;+ init?(validatingUTF8CString: UnsafePointer&lt;CUnsignedChar&gt;)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;}<br class="">
&gt;<br class="">
&gt; The properties would change to methods, overloaded by return type:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/StringUTF8.swift" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/StringUTF8.swift</a>&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;extension String {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;- var nulTerminatedUTF8CString: ContiguousArray&lt;CChar&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;- var nulTerminatedUTF8: ContiguousArray&lt;UTF8.CodeUnit&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;+ func utf8CString() -&gt; ContiguousArray&lt;CSignedChar&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;+ func utf8CString() -&gt; ContiguousArray&lt;CUnsignedChar&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;}<br class="">
&gt;<br class="">
&gt; ## NOTES ##<br class="">
&gt;<br class="">
&gt; UTF8.CodeUnit is defined as UInt8, and CChar is currently defined as Int8:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/CTypes.swift" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/CTypes.swift</a>&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;/// The C 'char' type.<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;///<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;/// This will be the same as either `CSignedChar` (in the common<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;/// case) or `CUnsignedChar`, depending on the platform.<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;public typealias CChar = Int8<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;/// The C 'signed char' type.<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;public typealias CSignedChar = Int8<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;/// The C 'unsigned char' type.<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;public typealias CUnsignedChar = UInt8<br class="">
&gt;<br class="">
&gt; There's an abandoned proposal to update CChar:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/7925/focus=8158" rel="noreferrer" target="_blank" class="">http://thread.gmane.org/gmane.comp.lang.swift.evolution/7925/focus=8158</a>&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/8419" rel="noreferrer" target="_blank" class="">http://thread.gmane.org/gmane.comp.lang.swift.evolution/8419</a>&gt;<br class="">
&gt;<br class="">
&gt; String.init(cString: UnsafePointer&lt;UInt8&gt;) and nulTerminatedUTF8CString were added by SE-0107:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#cstring-conversion" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#cstring-conversion</a>&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://github.com/apple/swift/commit/c7aa8284c905a73959ad69255cb56c38db80d039" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/commit/c7aa8284c905a73959ad69255cb56c38db80d039</a>&gt;<br class="">
&gt;<br class="">
&gt; Foundation.NSString uses the `utf8String` name instead:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://developer.apple.com/reference/foundation/nsstring/1412128-init" rel="noreferrer" target="_blank" class="">https://developer.apple.com/reference/foundation/nsstring/1412128-init</a>&gt;<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="https://developer.apple.com/reference/foundation/nsstring/1411189-utf8string" rel="noreferrer" target="_blank" class="">https://developer.apple.com/reference/foundation/nsstring/1411189-utf8string</a>&gt;<br class="">
<br class="">
&lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md</a>&gt;<br class="">
<br class="">
There's another method for SE-0134 which could be renamed or removed:<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &lt;<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/LifetimeManager.swift" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/blob/master/stdlib/public/core/LifetimeManager.swift</a>&gt;<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; extension String {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; - func withCString&lt;Result&gt;(<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; -&nbsp; &nbsp;_ body: @noescape (UnsafePointer&lt;Int8&gt;) throws -&gt; Result<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; - ) rethrows -&gt; Result<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; + func withUTF8CString&lt;Result&gt;(<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; +&nbsp; &nbsp;_ body: @noescape (UnsafePointer&lt;CSignedChar&gt;) throws -&gt; Result<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; + ) rethrows -&gt; Result<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; + func withUTF8CString&lt;Result&gt;(<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; +&nbsp; &nbsp;_ body: @noescape (UnsafePointer&lt;CUnsignedChar&gt;) throws -&gt; Result<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; + ) rethrows -&gt; Result<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">
<br class="">
The overloads (CSignedChar and CUnsignedChar) are needed if CChar will become UInt8 on some platforms.<br class="">
<br class="">
-- Ben<br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>