<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=""><div class="">Does it? According to the documentation for the&nbsp;<a href="https://developer.apple.com/reference/swift/string/1641442-decodecstring" class="">current decodeCString</a>, it seems to accept an UnsafePointer, not a buffer pointer, and expects the string to be null-terminated. Am I missing another overload?</div><br class=""><div><blockquote type="cite" class=""><div class="">Le 30 mars 2017 à 17:27, Zach Waldowski 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="">


<title class=""></title>

<div class=""><div style="font-family:Arial;" class="">On Thu, Mar 30, 2017, at 12:35 PM, Félix Cloutier via swift-evolution wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">I don't have much non-nitpick issues that I greatly care about; I'm in favor of this.<br class=""></div>
<div class=""><br class=""></div>
<div class="">My only request: it's currently painful to create a String from a fixed-size C array. For instance, if I have a pointer to a `struct foo { char name[16]; }` in Swift where the last character doesn't have to be a NUL, it's hard to create a String from it. Real-world examples of this are Mach-O LC_SEGMENT and LC_SEGMENT_64 commands.<br class=""></div>
<div style="font-family:Arial;" class=""><br class=""></div>
<div class=""><br class=""></div>
<div class="">The&nbsp;<a href="http://stackoverflow.com/a/27456220/251153" class="">generally-accepted wisdom</a>&nbsp;is that you take a pointer to the CChar tuple that represents the fixed-size array, but this still requires the string to be NUL-terminated. What do we think of an additional init(cString:) overload that takes an UnsafeBufferPointer and reads up to the first NUL or the end of the buffer, whichever comes first?<br class=""></div>
</blockquote><div style="font-family:Arial;" class=""><br class=""></div>
<div style="font-family:Arial;" class="">Today's String already supports this through `String.decodeCString(_:as:repairingInvalidCodeUnits:)`, passing a buffer pointer.<br class=""></div>
<div style="font-family:Arial;" class=""><div style="font-family:Arial;" class=""><div style="font-family:Arial;" class=""><br class=""></div>
</div>
<div id="sig40804545" class=""><div class="signature"><span class="font" style="font-family:arial, sans-serif, sans-serif">Best,</span><br class=""></div>
<div class="signature"><span class="font" style="font-family:arial, sans-serif, sans-serif">&nbsp; Zachary Waldowski</span><br class=""></div>
<div class="signature"><span class="font" style="font-family:arial, sans-serif, sans-serif">&nbsp;&nbsp;</span><a href="mailto:zach@waldowski.me" class=""><span class="font" style="font-family:arial, sans-serif, sans-serif">zach@waldowski.me</span></a><br class=""></div>
</div>
<div class=""><div style="font-family:Arial;" class=""><br class=""></div>
</div>
<div class=""><div style="font-family:Arial;" class=""><br class=""></div>
</div>
</div>
<div style="font-family:Arial;" class=""><br class=""></div>
</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>