Why the hell doesn't foreach decode strings
Jerry
jlquinn at optonline.net
Fri Oct 21 11:20:06 PDT 2011
"Martin Nowak" <dawg at dawgfoto.de> writes:
> Incidentally this has brought me a nice idea.
> You need to combine the foreach loop 'bug' with the ability to alter
> the index variable
> (http://d.puremagic.com/issues/show_bug.cgi?id=6652).
> Then you can construct a terrifically fast, still correct, utf8 decoder.
>
> foreach(i, c; s)
> {
> if (c < 0x80)
> outp.put(c);
> else
> (outp.put(std.utf.decode(s, i)), --i);
> }
>
Or even simpler:
foreach (dchar c; s)
outp.put(c);
foreach supports decoding built into the language.
Jerry
More information about the Digitalmars-d
mailing list