www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Unicode -> Windows 1252

reply Tom <tom nospam.com> writes:
I have a D2 code that writes some stuff to the screen (usually runs in 
cmd.exe pseudo-console). When I print spanish characters they show wrong 
(gibberish symbols and so, wich corresponds to CP-1252 encoding).

Is there a way to convert all outputted streams to CP-1252 without 
having to wrap writeln function (and replacing all its calls)?

TIA,

Tom;
Mar 16 2011
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
import std.c.windows.windows;
extern(Windows) BOOL SetConsoleOutputCP(UINT);
SetConsoleOutputCP(65001);
Mar 16 2011
parent reply Tom <tom nospam.com> writes:
El 16/03/2011 19:27, Andrej Mitrovic escribió:
 import std.c.windows.windows;
 extern(Windows) BOOL SetConsoleOutputCP(UINT);
 SetConsoleOutputCP(65001);
Tried a bunch of values and all yields the same result. Thanks anyway.
Mar 16 2011
parent reply Tom <tom nospam.com> writes:
El 16/03/2011 20:36, Tom escribió:
 El 16/03/2011 19:27, Andrej Mitrovic escribió:
 import std.c.windows.windows;
 extern(Windows) BOOL SetConsoleOutputCP(UINT);
 SetConsoleOutputCP(65001);
Tried a bunch of values and all yields the same result. Thanks anyway.
Forget it, I'll just use chcp...
Mar 16 2011
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 3/17/11, Tom <tom nospam.com> wrote:
 El 16/03/2011 20:36, Tom escribi=F3:
 El 16/03/2011 19:27, Andrej Mitrovic escribi=F3:
 import std.c.windows.windows;
 extern(Windows) BOOL SetConsoleOutputCP(UINT);
 SetConsoleOutputCP(65001);
Tried a bunch of values and all yields the same result. Thanks anyway.
Forget it, I'll just use chcp...
You probably already know this, but you can do that programmatically: import std.process; void main() { system("chcp 1252"); }
Mar 16 2011
parent Tom <tom nospam.com> writes:
El 16/03/2011 21:21, Andrej Mitrovic escribió:
 On 3/17/11, Tom<tom nospam.com>  wrote:
 El 16/03/2011 20:36, Tom escribió:
 El 16/03/2011 19:27, Andrej Mitrovic escribió:
 import std.c.windows.windows;
 extern(Windows) BOOL SetConsoleOutputCP(UINT);
 SetConsoleOutputCP(65001);
Tried a bunch of values and all yields the same result. Thanks anyway.
Forget it, I'll just use chcp...
You probably already know this, but you can do that programmatically: import std.process; void main() { system("chcp 1252"); }
Yeah. And by the way, SetConsoleOutputCP(65001) worked! Don't know what I did the first time I tried it. Another question: is there a way to hook a function or delegate before every output of the program, so I can filter the output in some way? Tom;
Mar 16 2011
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Otherwise you might be interested in using the WinAPI library from
dsource which has that function prototype and many others:
http://www.dsource.org/projects/bindings/wiki/WindowsApi
Mar 16 2011
parent Tom <tom nospam.com> writes:
El 16/03/2011 19:27, Andrej Mitrovic escribió:
 Otherwise you might be interested in using the WinAPI library from
 dsource which has that function prototype and many others:
 http://www.dsource.org/projects/bindings/wiki/WindowsApi
Mmh, the whole winapi just for that seems a little too much. :S
Mar 16 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Sorry, 65001 is actually UTF-8 or UTF-7 IIRC. For CP-1252 you'll have
to find the correct value, I guess.
Mar 16 2011
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 16/03/2011 22:17, Tom wrote:
 I have a D2 code that writes some stuff to the screen (usually runs in cmd.exe
 pseudo-console). When I print spanish characters they show wrong (gibberish
symbols and
 so, wich corresponds to CP-1252 encoding).

 Is there a way to convert all outputted streams to CP-1252 without having to
wrap writeln
 function (and replacing all its calls)?
My utility library has a console I/O module that converts to/from the console codepage under Windows: http://pr.stewartsplace.org.uk/d/sutil/ See if it's useful to you. I'm not sure whether it works under D2, but it's probably quite straightforward to tweak it so that it does. Stewart.
Mar 18 2011
parent Tom <tom nospam.com> writes:
El 18/03/2011 21:15, Stewart Gordon escribió:
 On 16/03/2011 22:17, Tom wrote:
 I have a D2 code that writes some stuff to the screen (usually runs in
 cmd.exe
 pseudo-console). When I print spanish characters they show wrong
 (gibberish symbols and
 so, wich corresponds to CP-1252 encoding).

 Is there a way to convert all outputted streams to CP-1252 without
 having to wrap writeln
 function (and replacing all its calls)?
My utility library has a console I/O module that converts to/from the console codepage under Windows: http://pr.stewartsplace.org.uk/d/sutil/ See if it's useful to you. I'm not sure whether it works under D2, but it's probably quite straightforward to tweak it so that it does. Stewart.
Thanks! I'll give it a try. Tom;
Mar 21 2011