<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="">Thanks ..seeing now all this being heavily intertwined with external libs ICU etc.</div><div class="">then yes, too much effort for too little (making fixed width Unicode strings)</div><div class="">Why am i doing this? &nbsp;Unicode is a wasp nest, how do you survive, Dave ? :o)&nbsp;</div><div class=""><br class=""></div><div class="">But I do use “random string access" e.g. extracting substrings</div><div class="">with e.g. &nbsp;let part = str[3..&lt;6] &nbsp;</div><div class="">with the help of the aforementioned String extension..</div><div class=""><br class=""></div><div class=""><div class="">arrgh, great, make me a tea...</div></div><div class=""><br class=""></div><div class="">TedvG</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 6 Feb 2017, at 23:25, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Mon Feb 06 2017, David Waite &lt;<a href="http://david-AT-alkaline-solutions.com" class="">david-AT-alkaline-solutions.com</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Feb 6, 2017, at 10:26 AM, Ted F.A. van Gaalen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;<br class=""></blockquote>wrote:<br class=""><blockquote type="cite" class=""><br class="">Hi Dave,<br class="">Oops! yes, you’re right!<br class="">I did read again more thoroughly about Unicode <br class=""></blockquote><br class=""><blockquote type="cite" class="">and how Unicode is handled within Swift...<br class="">-should have done that before I write something- sorry. &nbsp;<br class=""><br class="">Nevertheless: <br class=""><br class="">How about this solution: &nbsp;(if I am not making other omissions in my thinking again) <br class="">-Store the string as a collection of fixed-width 32 bit UTF-32 characters anyway.<br class="">-however, if the Unicode character is a grapheme cluster (2..n Unicode characters),then <br class="">store a pointer to a hidden child string containing the actual grapheme cluster, like so:<br class=""><br class="">1: [UTF32, UTF32, UTF32, 1pointer, &nbsp;UTF32, UTF32, 1pointer, UTF32, UTF32]<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<br class="">2: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[UTF32, UTF32] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[UTF32, UTF32, UTF32, ...]<br class=""><br class="">whereby (1) is aString as seen by the programmer.<br class="">and (2) &nbsp;are hidden child strings, each containing a grapheme cluster. <br class=""></blockquote><br class="">The random access would require a uniform layout, so a pointer and<br class="">scalar would need to be the same size. The above would work with a 32<br class="">bit platform with a tagged pointer, but would require a 64-bit slot<br class="">for pointers on 64-bit systems like macOS and iOS.<br class=""></blockquote><br class="">It would also make String not efficiently interoperable with almost any<br class="">other system that processes strings including Foundation and ICU.<br class=""><br class=""><blockquote type="cite" class="">Today when I need to do random access into a string, I convert it to<br class="">an Array&lt;Character&gt;. Hardly efficient memory-wise, but efficient<br class="">enough for random access.<br class=""></blockquote><br class="">I'd be willing to bet almost anything that you &nbsp;never actually need to<br class="">do random access into a String ;-)<br class=""><br class="">-- <br class="">-Dave<br class=""></div></div></blockquote></div><br class=""></div></body></html>