<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div style="direction: inherit;">IIUC, Jay wasn't arguing for renaming CharacterSet, but replacing it with Swift's existing Set mechanism. If/when generics get to the point that we can say 'extension Set&lt;Character&gt; {...}', I think the transition could simply be putting 'typealias CharacterSet = Set&lt;Character&gt;' somewhere in the framework (although I don't know how Obj-C interop would be affected by such a change).</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">- Dave Sweeris</div></div><div><br>On Sep 29, 2016, at 00:30, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>CharacterSet is a Foundation value type. It was a subject of the following proposal:<br><br><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0069-swift-mutability-for-foundation.md">https://github.com/apple/swift-evolution/blob/master/proposals/0069-swift-mutability-for-foundation.md</a><br><br>We might be able improve on the implementation, but I don't think re-arguing the name is an option.<br><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 28, 2016 at 11:59 PM Jay Abbott &lt;<a href="mailto:jay@abbott.me.uk">jay@abbott.me.uk</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br>Yes - this is totally confusing. CharacterSet and Set&lt;Character&gt; are completely different things with different semantics.<br><br></div>I don't know the history, but is CharacterSet simply to have a Swift equivalent of NSCharacterSet? That seems to be what it is, but since Swift redefined characters in a better way, this should be removed or called something else to avoid confusion. You shouldn't have to qualify what you mean by 'character' in a type name because it diverges from the definition in the rest of the language.<br></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 29 Sep 2016 at 04:48 Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">On Wed, Sep 28, 2016 at 10:34 PM, Xiaodi Wu <span dir="ltr">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span> wrote:<br></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><span>On Wed, Sep 28, 2016 at 10:23 PM, Charles Srstka via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><span><blockquote type="cite">On Sep 28, 2016, at 9:57 PM, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></blockquote><div><blockquote type="cite"><br><div><span style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">D'erp. I missed that. And that's an unambiguous answer.</span><br style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">So let me move on to part B of the pitch: I think CharacterSets are broken.</span><br style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite" style="font-family:helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Xiaodi Wu: "isn't the problem you're presenting really an argument that the type should be fleshed out to handle characters (grapheme clusters) containing more than one Unicode scalar?"</blockquote></div></blockquote></div><br></span><div>It seems that it already does handle such characters:</div><div><br></div><div>(done in Objective-C so we can log the length of the range as a count of UTF-16 code units)</div><div><br></div><div><div style="margin:0px;line-height:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="color:rgb(120,73,42)">#import </span><span>&lt;Foundation/Foundation.h&gt;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(186,45,162)">int</span><span> main(</span><span style="color:rgb(186,45,162)">int</span><span> argc, </span><span style="color:rgb(186,45,162)">char</span><span> *argv[]) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="color:rgb(0,0,0)">&nbsp; &nbsp; </span><span>@autoreleasepool</span><span style="color:rgb(0,0,0)"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(62,30,129)"><span style="color:rgb(0,0,0)">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(112,61,170)">NSCharacterSet</span><span style="color:rgb(0,0,0)"> *bikeSet = [</span><span style="color:rgb(112,61,170)">NSCharacterSet</span><span style="color:rgb(0,0,0)"> </span><span>characterSetWithCharactersInString</span><span style="color:rgb(0,0,0)">:</span><span style="color:rgb(209,47,27)">@"</span><span style="line-height:normal;font-family:'apple color emoji';color:rgb(209,47,27)">🚲</span><span style="color:rgb(209,47,27)">"</span><span style="color:rgb(0,0,0)">];</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(112,61,170)">NSString</span><span> *str = </span><span style="color:rgb(209,47,27)">@"foo</span><span style="line-height:normal;font-family:'apple color emoji';color:rgb(209,47,27)">🚲</span><span style="color:rgb(209,47,27)">bar"</span><span>;</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(112,61,170)">NSRange</span><span> range = [str </span><span style="color:rgb(62,30,129)">rangeOfCharacterFromSet</span><span>:bikeSet];</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:rgb(62,30,129)">NSLog</span><span style="color:rgb(0,0,0)">(</span><span>@"location: %lu length: %lu"</span><span style="color:rgb(0,0,0)">, range.</span><span style="color:rgb(112,61,170)">location</span><span style="color:rgb(0,0,0)">, range.</span><span style="color:rgb(112,61,170)">length</span><span style="color:rgb(0,0,0)">);</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>&nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div></div></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">- - - - - - -</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><b>2016-09-28 22:20:00.622471 test[15577:2433912] location: 3 length: 2</b></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><b>Program ended with exit code: 0</b></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><b><br></b></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><span style="font-family:helvetica;font-size:12px">- - - - - - -</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><span style="font-family:helvetica;font-size:12px"><br></span></span></div><div style="margin:0px;line-height:normal"><span>As we can see, the character from the set is recognized as consisting of two code units. There are a few bugs in the system, though. See the cocoa-dev thread&nbsp;β€œWhere is my bicycle?” from about a year ago:&nbsp;</span><a href="http://prod.lists.apple.com/archives/cocoa-dev/2015/Apr/msg00074.html" target="_blank">http://prod.lists.apple.com/archives/cocoa-dev/2015/Apr/msg00074.html</a></div></div></div></div></blockquote><div><br></div></span><div>The bike emoji might be two code units, but it is one Unicode scalar (U+1F6B2). However, the Canadian flag emoji, for instance, is two Unicode scalars (U+1F1E8 U+1F1E6) but nonetheless one character.</div></div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>To illustrate in code how CharacterSet doesn't actually handle characters made up of multiple Unicode scalars:</div><div><br></div><div>```</div><div>import Foundation</div><div><br></div><div><div>let str1 = "πŸ‡¦πŸ‡©"</div><div>let first = CharacterSet(charactersIn: str1) // this actually crashes corelibs-foundation</div><div>let str2 = "πŸ‡¦πŸ‡Ί"</div><div>let second = CharacterSet(charactersIn: str2)</div><div>let intersection = first.intersection(second)</div><div>print(intersection.isEmpty)</div></div><div>// actual output: false</div><div>// obviously, if we were really dealing with characters, the intersection should be empty</div><div>```</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"></div><div style="margin:0px;line-height:normal">Charles</div><div style="margin:0px;line-height:normal"><br></div></div></div></div><span><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>
<br></span></blockquote></div><br></div></div>
</blockquote></div></div></div>
_______________________________________________<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>
</blockquote></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>