<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="">Hi Dave,</div><div class="">Oops! yes, you’re right!</div><div class="">I did read again more thoroughly about Unicode </div><div class="">and how Unicode is handled within Swift...</div><div class="">-should have done that before I write something- sorry. </div><div class=""><br class=""></div><div class="">Nevertheless: </div><div class=""><br class=""></div><div class="">How about this solution: (if I am not making other omissions in my thinking again) </div><div class="">-Store the string as a collection of fixed-width 32 bit UTF-32 characters anyway.</div><div class="">-however, if the Unicode character is a grapheme cluster (2..n Unicode characters),then </div><div class="">store a pointer to a hidden child string containing the actual grapheme cluster, like so:</div><div class=""><br class=""></div><div class="">1: [UTF32, UTF32, UTF32, 1pointer, UTF32, UTF32, 1pointer, UTF32, UTF32]</div><div class=""> | |</div><div class="">2: [UTF32, UTF32] [UTF32, UTF32, UTF32, ...]</div><div class=""><br class=""></div><div class="">whereby (1) is aString as seen by the programmer.</div><div class="">and (2) are hidden child strings, each containing a grapheme cluster. </div><div class=""><br class=""></div><div class="">To make the distinction between a “plain” single UTF-32 char and a grapheme cluster, </div><div class="">set the most significant bit of the 32 bit value to 1 and use the other 31 bits</div><div class="">as a pointer to another (hidden) String instance, containing the grapheme cluster. </div><div class="">In this way, one could then also make graphemes within graphemes, </div><div class="">but that is probably not desired? Another solution is to store the grapheme clusters</div><div class="">in a dedicated “grapheme pool’, containing the (unique as in aSet) grapheme clusters</div><div class="">encountered whenever a Unicode string (in whatever format) is read-in or defined at runtime. </div><div class=""><br class=""></div><div class="">but then again.. seeing how hard it is to recognise Grapheme clusters in the first place.. </div><div class="">? I don’t know. Unicode is complicated.. </div><div class=""><br class=""></div><div class="">Kind regards </div><div class="">TedvG. </div><div class=""><br class=""></div><div class=""><a href="http://www.tedvg.com" class="">www.tedvg.com</a></div><div class=""><a href="http://www.ravelnotes.com" class="">www.ravelnotes.com</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 6 Feb 2017, at 05:15, Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><br class=""><blockquote type="cite" class="">On Feb 5, 2017, at 2:57 PM, Ted F.A. van Gaalen <<a href="mailto:tedvgiosdev@gmail.com" class="">tedvgiosdev@gmail.com</a>> wrote:<br class=""><br class="">However, that is not the case with UTF-32, because with UTF-32 encoding<br class="">each character has a fixed-width and always occupies exactly 4 bytes, 32 bit. <br class="">Ergo: the problem can be easily solved: The simple solution is to always <br class="">and without exception use UTF-32 encoding as Swift's internal <br class="">string format because it only contains fixed width Unicode characters. <br class=""></blockquote><br class="">Those are not (user-perceived) Characters; they are Unicode Scalar Values (often called "characters" by the Unicode standard. Characters as defined in Swift (a.k.a. extended grapheme clusters) have no fixed-width encoding, and Unicode scalar values are an inappropriate unit for most string processing. Please read the manifesto for details.<br class=""><br class="">Sent from my iPad<br class=""></div></div></blockquote></div><br class=""></body></html>