<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? Unicode is a wasp nest, how do you survive, Dave ? :o) </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. let part = str[3..<6] </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 <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Mon Feb 06 2017, David Waite <<a href="http://david-AT-alkaline-solutions.com" class="">david-AT-alkaline-solutions.com</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>><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. <br class=""><br class="">Nevertheless: <br class=""><br class="">How about this solution: (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, UTF32, UTF32, 1pointer, UTF32, UTF32]<br class=""> | |<br class="">2: [UTF32, UTF32] [UTF32, UTF32, UTF32, ...]<br class=""><br class="">whereby (1) is aString as seen by the programmer.<br class="">and (2) 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<Character>. 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 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>