Re: foreach over string

2014-05-24 Thread Kagamin via Digitalmars-d-learn
On Saturday, 24 May 2014 at 18:18:37 UTC, John Colvin wrote: if you use foreach(dchar c; s) you will get the iteration by code-point you are looking for. Actually I was trying to prevent decoding :) It just occurred to me it can be tricky in generic code.

Re: foreach over string

2014-05-24 Thread John Colvin via Digitalmars-d-learn
On Saturday, 24 May 2014 at 16:46:42 UTC, Kagamin wrote: foreach over string apparently iterates over chars by default instead of dchars. Didn't it prefer dchars? string s="weiß"; int i; foreach(c;s)i++; assert(i==5); Nope. if you use foreach(dchar c; s) you will get the ite

Re: foreach over string

2014-05-24 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 09:46 AM, Kagamin wrote: foreach over string apparently iterates over chars by default instead of dchars. Didn't it prefer dchars? I don't think so. The range algorithms iterate by dchar though. string s="weiß"; int i; foreach(c;s)i++; assert(i==5); Ali

Re: foreach over string

2014-05-24 Thread Etienne Cimon via Digitalmars-d-learn
On 2014-05-24 12:46, Kagamin wrote: foreach over string apparently iterates over chars by default instead of dchars. Didn't it prefer dchars? string s="weiß"; int i; foreach(c;s)i++; assert(i==5); A string is defined by: alias string = immutable(char)[]; It doesn't add a

foreach over string

2014-05-24 Thread Kagamin via Digitalmars-d-learn
foreach over string apparently iterates over chars by default instead of dchars. Didn't it prefer dchars? string s="weiß"; int i; foreach(c;s)i++; assert(i==5);

Re: foreach over string enum

2011-02-20 Thread Daniel Murphy
"Jesse Phillips" wrote in message news:ij2drt$1mq3$1...@digitalmars.com... > > Magic. > > No really, the best I can tell is that the compiler will try to run the > foreach loop at compile-time if there is something in the body that must > be evaluated at compile time. > Actually this happens b

Re: foreach over string enum

2011-02-11 Thread spir
On 02/11/2011 05:27 AM, Jesse Phillips wrote: spir Wrote: But in your example the symbol a does not look like a constant, instead it the loop variable. Do, how does it work? Magic. No really, the best I can tell is that the compiler will try to run the foreach loop at compile-time if there

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
spir Wrote: > But in your example the symbol a does not look like a constant, instead it > the > loop variable. Do, how does it work? Magic. No really, the best I can tell is that the compiler will try to run the foreach loop at compile-time if there is something in the body that must be eva

Re: foreach over string enum

2011-02-10 Thread spir
On 02/11/2011 01:02 AM, Ali Çehreli wrote: I don't have answers to your other questions. On 02/10/2011 03:25 PM, spir wrote: unittest { auto i = 1; auto s = "i"; It works if you define s as: enum s = "i"; writeln(mixin("i")); // compiler happy up to here --> "1" writeln(mixin(s)); //

Re: foreach over string enum

2011-02-10 Thread Ali Çehreli
I don't have answers to your other questions. On 02/10/2011 03:25 PM, spir wrote: > unittest { > auto i = 1; > auto s = "i"; It works if you define s as: enum s = "i"; > writeln(mixin("i")); // compiler happy up to here --> "1" > writeln(mixin(s)); // compiler unhappy --> "Error: argument

Re: foreach over string enum

2011-02-10 Thread spir
On 02/10/2011 11:32 PM, Jesse Phillips wrote: enum FileName : string { > > file1 = "file1.ext", > > file2 = "file2.ext" > > } > > > > void main(string args[]) > > { > >foreach(a; __traits(allMembers, FileName)) > >writeln(mixin("FileName." ~ a)); > > } > > Why

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
spir Wrote: > On 02/10/2011 08:22 PM, Jesse Phillips wrote: > > enum FileName : string { > > file1 = "file1.ext", > > file2 = "file2.ext" > > } > > > > void main(string args[]) > > { > > foreach(a; __traits(allMembers, FileName)) > > writeln(mixin("FileName." ~ a)); > > } > > Why t

Re: foreach over string enum

2011-02-10 Thread spir
On 02/10/2011 08:22 PM, Jesse Phillips wrote: Nrgyzer Wrote: Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = "file1.ext", file2 = "file2.ext" } I already found this article: http://lists.puremagic.com/pipermail/ digit

Re: foreach over string enum

2011-02-10 Thread Nrgyzer
== Auszug aus Jesse Phillips (jessekphillip...@gmail.com)'s Artikel > Nrgyzer Wrote: > > Hey guys, > > > > I'm trying to iterate over an enumeration which contains strings like > > the this: > > > > enum FileName : string { > > file1 = "file1.ext", > > file2 = "file2.ext" > > } > > > > I already fo

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
Nrgyzer Wrote: > Hey guys, > > I'm trying to iterate over an enumeration which contains strings like > the this: > > enum FileName : string { > file1 = "file1.ext", > file2 = "file2.ext" > } > > I already found this article: http://lists.puremagic.com/pipermail/ > digitalmars-d/2007-July/021920

foreach over string enum

2011-02-10 Thread Nrgyzer
Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = "file1.ext", file2 = "file2.ext" } I already found this article: http://lists.puremagic.com/pipermail/ digitalmars-d/2007-July/021920.html but it's an enum which contains in