retro() on a `string` creates a range of `dchar`, causing array() pains

Ali Çehreli acehreli at yahoo.com
Tue Apr 17 09:09:40 PDT 2012


On 04/17/2012 08:58 AM, bearophile wrote:
 > Ali Çehreli:
 >
 >> The reason is, a sequence of UTF-8 code units are not a valid UTF-8
 >> when reversed (or retro'ed :p).
 >
 > But reversed(char[]) now works :-)

That's pretty cool. :) (You meant reverse()).

Interesting, because there could be no other way anyway because 
reverse() is in-place. Iterating by dchar without damaging the other end 
must have been challenging because the first half of the string may have 
been all multi-bype UTF-8 code units and all of the rest of single-bytes.

The algorithm must be building a local string.

 > Bye,
 > bearophile

Ali



More information about the Digitalmars-d-learn mailing list