<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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
> On 25 Jul 2016, at 15:27, Ben Rimmington wrote:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> My suggestion for SE-0134 is to use the `utf8CString` name, overloading for CSignedChar and CUnsignedChar:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> extension String {<br class="">
> - init(cString: UnsafePointer<CChar>)<br class="">
> - init(cString: UnsafePointer<UInt8>)<br class="">
> - init?(validatingUTF8 cString: UnsafePointer<CChar>)<br class="">
><br class="">
> + init(utf8CString: UnsafePointer<CSignedChar>)<br class="">
> + init(utf8CString: UnsafePointer<CUnsignedChar>)<br class="">
> + init?(validatingUTF8CString: UnsafePointer<CSignedChar>)<br class="">
> + init?(validatingUTF8CString: UnsafePointer<CUnsignedChar>)<br class="">
> }<br class="">
><br class="">
> The properties would change to methods, overloaded by return type:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> extension String {<br class="">
> - var nulTerminatedUTF8CString: ContiguousArray<CChar><br class="">
> - var nulTerminatedUTF8: ContiguousArray<UTF8.CodeUnit><br class="">
><br class="">
> + func utf8CString() -> ContiguousArray<CSignedChar><br class="">
> + func utf8CString() -> ContiguousArray<CUnsignedChar><br class="">
> }<br class="">
><br class="">
> ## NOTES ##<br class="">
><br class="">
> UTF8.CodeUnit is defined as UInt8, and CChar is currently defined as Int8:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> /// The C 'char' type.<br class="">
> ///<br class="">
> /// This will be the same as either `CSignedChar` (in the common<br class="">
> /// case) or `CUnsignedChar`, depending on the platform.<br class="">
> public typealias CChar = Int8<br class="">
><br class="">
> /// The C 'signed char' type.<br class="">
> public typealias CSignedChar = Int8<br class="">
><br class="">
> /// The C 'unsigned char' type.<br class="">
> public typealias CUnsignedChar = UInt8<br class="">
><br class="">
> There's an abandoned proposal to update CChar:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> <<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>><br class="">
><br class="">
> String.init(cString: UnsafePointer<UInt8>) and nulTerminatedUTF8CString were added by SE-0107:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> <<a href="https://github.com/apple/swift/commit/c7aa8284c905a73959ad69255cb56c38db80d039" rel="noreferrer" target="_blank" class="">https://github.com/apple/swift/commit/c7aa8284c905a73959ad69255cb56c38db80d039</a>><br class="">
><br class="">
> Foundation.NSString uses the `utf8String` name instead:<br class="">
><br class="">
> <<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>><br class="">
><br class="">
> <<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>><br class="">
<br class="">
<<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>><br class="">
<br class="">
There's another method for SE-0134 which could be renamed or removed:<br class="">
<br class="">
<<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>><br class="">
<br class="">
extension String {<br class="">
- func withCString<Result>(<br class="">
- _ body: @noescape (UnsafePointer<Int8>) throws -> Result<br class="">
- ) rethrows -> Result<br class="">
<br class="">
+ func withUTF8CString<Result>(<br class="">
+ _ body: @noescape (UnsafePointer<CSignedChar>) throws -> Result<br class="">
+ ) rethrows -> Result<br class="">
<br class="">
+ func withUTF8CString<Result>(<br class="">
+ _ body: @noescape (UnsafePointer<CUnsignedChar>) throws -> Result<br class="">
+ ) rethrows -> Result<br class="">
}<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>