www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1448] New: UTF-8 output to console is seriously broken

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448

           Summary: UTF-8 output to console is seriously broken
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: a.solovey gmail.com


If windows console code page is set to 65001 (UTF-8) and program outputs
non-ascii characters in UTF-8 encoding, there will be no more output after the
first new line after accented character. I believe that problem is in
underlying DMC stdio, but it is more disturbing with D as it has good Unicode
support and it is very convenient to work international texts in it.
This problem has been reported in newsgroup several times before, see for
example
http://www.digitalmars.com/d/archives/digitalmars/D/announce/openquran_v0.21_8492.html
Here is the code to illustrate the problem:
////////
import std.c.stdio;
import std.c.windows.windows;

extern(Windows) export BOOL SetConsoleOutputCP( UINT );

void main() {
    SetConsoleOutputCP( 65001 ); // or use "chcp 65001" instead
    // Codepoint 00e9 is "Latin small letter e with acute"
    puts( "Output utf-8 accented char \u00e9\n... and the rest is cut off!\n"
);
}
/////////
If you run it, "... and the rest is cut off!" won't be displayed. Do not forget
to set console font to Lucida Console before trying this.


-- 
Aug 28 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448





------- Comment #1 from a.solovey gmail.com  2007-08-28 22:52 -------
Created an attachment (id=172)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=172&action=view)
Small test cae for the same problem in DMC


-- 
Aug 28 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com




------- Comment #2 from smjg iname.com  2007-08-29 13:03 -------
The problem doesn't show if I use the Windows API (either WriteConsole or
WriteFile) to output.  So the bug must be somewhere in DM's stdio
implementation.


-- 
Aug 29 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla digitalmars.com  2007-09-28 22:15 -------
Fixed dmd 1.021 and 2.004


-- 
Sep 28 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448


mk krej.cz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Comment #4 from mk krej.cz  2007-10-29 11:02 -------
The problem was NOT fixed for stderr (DMD 1.022)


-- 
Oct 29 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448


mk krej.cz changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mk krej.cz




------- Comment #5 from mk krej.cz  2007-10-29 11:04 -------
*** Bug 1608 has been marked as a duplicate of this bug. ***


-- 
Oct 29 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1448





------- Comment #6 from mk krej.cz  2008-09-03 10:57 -------
I hope this gets fixed one day. Here is an updated example, where it still
doesn't work (for stderr, stdout is ok) as of DMD 1.035

import std.c.stdio;
import std.c.windows.windows;

extern(Windows) export BOOL SetConsoleOutputCP( UINT );

void main() {
    SetConsoleOutputCP( 65001 ); // or use "chcp 65001" instead
    // Codepoint 00e9 is "Latin small letter e with acute"
    fputs("Output utf-8 accented char \u00e9\n... and the rest is OK\n",
stdout);
    fputs("Output utf-8 accented char \u00e9\n... and the rest is cut off!\n",
stderr);
    fputs("STDOUT.\n", stdout);
    fputs("STDERR.\n", stderr);
}


-- 
Sep 03 2008