TDPL: Foreach over Unicode string
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Jul 27 15:47:08 PDT 2010
On Wed, Jul 28, 2010 at 12:34 AM, Sean Kelly <sean at invisibleduck.org> wrote:
> Sean Kelly Wrote:
> >
> > I think it's Windows integration that's the problem, on OSX I get:
> >
> > [H][a][l][l][?][?][,][ ][V][?][?][r][l][d][!]
> > [H][a][l][l][å][,][ ][V][ä][r][l][d][!]
> >
> > which is essentially correct. The only difference between this and doing
> the same thing in C and using printf() in place of write() is that both
> lines display correctly in C. I think printf() must be detecting partial
> UTF-8 characters and buffering until the complete chunk has arrived.
> Interestingly, the C output can't even be broken by badly timed calls to
> fflush(), so the buffering is happening at a fairly high level. I'd be
> interested in seeing the same thing in write() at some point.
>
> Ah, write() already works that way. It was the brackets that were screwing
> things up.
>
You are right about printf(), I'm getting the correct output with this code:
import std.stdio, std.stream;
void main() {
string str = "Hall\u00E5, V\u00E4rld!";
foreach (dchar c; str) {
printf("%c", c);
}
writeln();
}
Hallå, Värld!
Should I file this as a Windows bug for DMD?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100728/387b2eca/attachment.html>
More information about the Digitalmars-d
mailing list