<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 4, 2560 BE, at 04:37, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_msg">On Sat, Apr 1, 2017 at 2:52 AM, Pitiphong Phongpattranont via swift-evolution<span class="Apple-converted-space"> </span><span class="gmail_msg"><<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>></span><span class="Apple-converted-space"> </span>wrote:<br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">Hello Swift Community,<br class="gmail_msg"><br class="gmail_msg">I’ve found a problem on Swift String API with Thai language. In Thai, we have 44 Consonants, 32 vowels and 5 tone marks. A special attribute of Thai vowels is that they can be put on anywhere around a consonant, some of them are placed after a consonant (ชา), some are before (แช), some are above (ชี) and some are below (ชุ). Since all vowels must be placed along with a consonants but they’re place in difference places around a consonant, Unicode standard says that some of the Thai vowels are Grapheme Base and some are Grapheme Extend.<br class="gmail_msg"><br class="gmail_msg">And because Swift String is fully Unicode compliance and by having some vowels be a Grapheme Extend makes some Thai vowels have a invalid attributes in some aspects. For example a word “ชี” (a nun) and “ชา” (tea) both have one consonant (in this case is ช) and one vowel (ี and า). When we ask how many characters are there in those words or does this word contain a ช character, we should get the same results from those 2 words (2 characters and it contains ช). However I found that in Swift String API, I will get a difference answers from those questions.<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">// You can try this code snippet in a Swift Playground<br class="gmail_msg">let chi = "ชี"<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">A Swift "character" models a Unicode extended grapheme cluster, which may or may not be a character with respect to a human language.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I don't speak Thai, but do you have a reference saying that the Unicode standard regards these as two separate extended grapheme clusters? Unless I'm mistaken, according to the reference (<a href="http://unicode.org/cldr/utility/character.jsp?a=0E35" class="gmail_msg" target="_blank">http://unicode.org/cldr/utility/character.jsp?a=0E35</a>), the combining vowel U+0E35 extends the grapheme cluster. Therefore, Unicode rules require this to be reported as one extended grapheme cluster, which would make this one single Swift "character". The remaining behaviors appear to be consistent with the Unicode standard as well.</div></div></div></div></div></div></blockquote><div><br class=""></div><div><div class="">I understand how Unicode and Grapheme Clusters work and also know the fact that Swift String is fully Unicode compliance. The problem I try to bring up is that even though the grapheme property of U+0E35 and U+0E32 are difference but in Thai language both vowels have the same properties which means that they should have the same Unicode properties and return the same results from the sample codes.</div><div class=""><br class=""></div><div class="">I understand this may be the problem in the Unicode specifications not on Swift. I just want to bring this issue up to the discussion so that this issue will be in the Swift team eyes and would take this issue into a discussion.</div></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">let cha = “ชา"<br class="gmail_msg"><br class="gmail_msg">// Value of these 2 lines below should be 2<br class="gmail_msg">chi.characters.count<br class="gmail_msg">cha.characters.count<br class="gmail_msg"><br class="gmail_msg">// Value of these 3 lines below should be true<br class="gmail_msg">chi.contains("ช")<br class="gmail_msg">cha.contains("ช")<br class="gmail_msg">chi.characters.contains("ช”)<br class="gmail_msg"><br class="gmail_msg">// end of code snippet<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">It sounds like you want to query by Unicode scalar, which you can do:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">```</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(112, 61, 170);" class=""><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">chi</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">unicodeScalars</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">contains</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"</span><span class="gmail_msg" style="font-stretch: normal; line-height: normal; font-family: ayuthaya; font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">ช</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">) // true</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(112, 61, 170);" class=""><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">cha</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">unicodeScalars</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">contains</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"</span><span class="gmail_msg" style="font-stretch: normal; line-height: normal; font-family: ayuthaya; font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">ช</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"</span><span class="gmail_msg" style="font-variant-ligatures: no-common-ligatures;">) // true</span></div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">From some brief reading, it appears that there's some disagreement about how Unicode treats Thai (<a href="http://www.thai-language.com/forums/t/linguistics/writing/t14254" class="gmail_msg" target="_blank">http://www.thai-language.com/forums/t/linguistics/writing/t14254</a>). However, Swift strictly implements Unicode, which would be the forum to consider any issues.</div></div></div></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">I’m not sure that if Swift team is aware of this problem and do they have any opinion on it. I know that Unicode is very very hard and do aware of that there would be a revamp on String API in Swift 4 so I want to make this into a discussion before Swift 4 is released.<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">Thank you,<br class="gmail_msg">Bank (Pitiphong)<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">_______________________________________________<br class="gmail_msg">swift-evolution mailing list<br class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></blockquote></div></div></div></div></div></blockquote></div><br class=""></body></html>