<div dir="ltr">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><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 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&#39;erp. I missed that. And that&#39;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: &quot;isn&#39;t the problem you&#39;re presenting really an argument that the type should be fleshed out to handle characters (grapheme clusters) containing more than one Unicode scalar?&quot;</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)">    </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)">        </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>characterSetWithCharactersInSt<wbr>ring</span><span style="color:rgb(0,0,0)">:</span><span style="color:rgb(209,47,27)">@&quot;</span><span style="line-height:normal;font-family:&#39;apple color emoji&#39;;color:rgb(209,47,27)">🚲</span><span style="color:rgb(209,47,27)">&quot;</span><span style="color:rgb(0,0,0)">];</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(112,61,170)">NSString</span><span> *str = </span><span style="color:rgb(209,47,27)">@&quot;foo</span><span style="line-height:normal;font-family:&#39;apple color emoji&#39;;color:rgb(209,47,27)">🚲</span><span style="color:rgb(209,47,27)">bar&quot;</span><span>;</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>        </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(112,61,170)">NSRange</span><span> range = [str </span><span style="color:rgb(62,30,129)">rangeOfCharacterFromSet</span><span>:bikeSe<wbr>t];</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>        </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)">        </span><span style="color:rgb(62,30,129)">NSLog</span><span style="color:rgb(0,0,0)">(</span><span>@&quot;location: %lu length: %lu&quot;</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>    }</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 “Where is my bicycle?” from about a year ago: </span><a href="http://prod.lists.apple.com/archives/cocoa-dev/2015/Apr/msg00074.html" target="_blank">http://prod.lists.apple.c<wbr>om/archives/cocoa-dev/2015/Apr<wbr>/msg00074.html</a></div></div></div></div></blockquote><div><br></div><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><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><br>______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>