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

Timon Gehr timon.gehr at gmx.ch
Tue Apr 17 09:12:18 PDT 2012


On 04/17/2012 06:09 PM, Ali Çehreli wrote:
> 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
>

It does not have to build a local string, see
http://dlang.org/phobos/std_utf.html#strideBack


More information about the Digitalmars-d-learn mailing list