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

Ali Çehreli acehreli at yahoo.com
Tue Apr 17 08:36:39 PDT 2012


On 04/17/2012 08:12 AM, Jakob Ovrum wrote:
 > Consider this simple function:
 >
 > private string findParameterList(string typestr)
 > {
 > auto strippedHead = typestr.find("(")[1 .. $];
 > auto strippedTail = retro(strippedHead).find(")");
 >
 > strippedTail.popFront(); // slice off closing parenthesis
 >
 > return array(strippedTail);
 > }
 >
 > The type of the return expression is dstring, not string.

The reason is, a sequence of UTF-8 code units are not a valid UTF-8 when 
reversed (or retro'ed :p). But a dchar array can be reversed.

Ali



More information about the Digitalmars-d-learn mailing list