Daniel Keep wrote:

Andrei Alexandrescu wrote:
Rainer Deyke wrote:
Sergey Gromov wrote:
To actually solve this problem the default exception handler must be
fixed to convert any UTF-8 into the current OEM code page before
printing.  It would also help if default stdin and stdout performed such
a conversion.
No, stdin/stdout *must* perform this conversion.  It is a serious bug if
they don't.

The conversion cannot be performed at any other level.  D uses unicode
internally.  The console uses a specific encoding.  Therefore all data
passing between D and the console must be encoded/decoded.


What API to use to detect the encoding used by the console?

Andrei

According to <http://markmail.org/message/neu2pllqz3sst4tq>, it's uint
GetConsoleOutputCP()
<http://msdn.microsoft.com/en-us/library/ms683169%28VS.85%29.aspx>.

Interestingly, there's a SetConsoleOutputCP
<http://msdn.microsoft.com/en-us/library/ms686036(VS.85).aspx> function.
 Check this out:

module utf;

import tango.io.Stdout;

extern(Windows) int SetConsoleOutputCP(uint wCodePageID);

void main()
{
    SetConsoleOutputCP(65001);
    Stdout("Не∟└Ω").newline;
}

FYI, "65001" is how Windows spells "UTF-8".  Also note that this won't
work in anything earlier than Windows 2000, but then, even that's not
supported any more.

Note that you MUST change the console's font to Lucidia Console
(right-click title, properties, font tab) for this to actually display,
but that's not something D can control.  :P

  -- Daniel

Ahhhh... Windows you mean? Ehm. I need to get to a Windows machine. If you could paste this into a bug report that would be great.

Thanks,

Andrei

Reply via email to