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

2012-04-18 Thread Ali Çehreli
On Wednesday, 18 April 2012 at 05:45:06 UTC, Jakob Ovrum wrote: > On Tuesday, 17 April 2012 at 15:36:39 UTC, Ali Çehreli wrote: >> >> 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 > > It is abs

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

2012-04-17 Thread Jakob Ovrum
On Tuesday, 17 April 2012 at 15:18:49 UTC, bearophile wrote: Jakob Ovrum: return array(strippedTail); } The type of the return expression is dstring, not string. What is the most elegant way or correct way to solve this friction? (Note: the function is used in CTFE)

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

2012-04-17 Thread Jakob Ovrum
On Tuesday, 17 April 2012 at 15:36:39 UTC, Ali Çehreli wrote: 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 It is absolutely possible to walk a UTF-8 string backwards. The problem here is that arr

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

2012-04-17 Thread Ali Çehreli
On 04/17/2012 09:12 AM, Timon Gehr wrote: > On 04/17/2012 06:09 PM, Ali Çehreli wrote: >> The algorithm must be building a local string. > It does not have to build a local string, see > http://dlang.org/phobos/std_utf.html#strideBack I never said otherwise. :p I was too lazy to locate where 2

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

2012-04-17 Thread Timon Gehr
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()

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

2012-04-17 Thread Ali Çehreli
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 w

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

2012-04-17 Thread bearophile
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 :-) Bye, bearophile

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

2012-04-17 Thread Ali Çehreli
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 >

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

2012-04-17 Thread bearophile
Jakob Ovrum: return array(strippedTail); } The type of the return expression is dstring, not string. What is the most elegant way or correct way to solve this friction? (Note: the function is used in CTFE) Try "text" instead of "array". Bye, bearophile

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

2012-04-17 Thread Jakob Ovrum
Consider this simple function: private string findParameterList(string typestr) { auto strippedHead = typestr.find("(")[1 .. $]; auto strippedTail = retro(strippedHead).find(")"); strippedTail.popFront(); // slice off closing parent