digitalmars.D.learn - Unicode -> Windows 1252
- Tom (7/7) Mar 16 2011 I have a D2 code that writes some stuff to the screen (usually runs in
- Andrej Mitrovic (3/3) Mar 16 2011 import std.c.windows.windows;
- Tom (3/6) Mar 16 2011 Tried a bunch of values and all yields the same result.
- Tom (2/8) Mar 16 2011 Forget it, I'll just use chcp...
- Andrej Mitrovic (7/17) Mar 16 2011 You probably already know this, but you can do that programmatically:
- Tom (6/26) Mar 16 2011 Yeah. And by the way, SetConsoleOutputCP(65001) worked!
- Andrej Mitrovic (3/3) Mar 16 2011 Otherwise you might be interested in using the WinAPI library from
- Tom (2/5) Mar 16 2011 Mmh, the whole winapi just for that seems a little too much. :S
- Andrej Mitrovic (2/2) Mar 16 2011 Sorry, 65001 is actually UTF-8 or UTF-7 IIRC. For CP-1252 you'll have
- Stewart Gordon (7/12) Mar 18 2011 My utility library has a console I/O module that converts to/from the co...
- Tom (4/20) Mar 21 2011 Thanks!
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
import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001);
Mar 16 2011
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
El 16/03/2011 20:36, Tom escribió:El 16/03/2011 19:27, Andrej Mitrovic escribió:Forget it, I'll just use chcp...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
On 3/17/11, Tom <tom nospam.com> wrote:El 16/03/2011 20:36, Tom escribi=F3:You probably already know this, but you can do that programmatically: import std.process; void main() { system("chcp 1252"); }El 16/03/2011 19:27, Andrej Mitrovic escribi=F3:Forget it, I'll just use chcp...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
El 16/03/2011 21:21, Andrej Mitrovic escribió:On 3/17/11, Tom<tom nospam.com> wrote: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;El 16/03/2011 20:36, Tom escribió:You probably already know this, but you can do that programmatically: import std.process; void main() { system("chcp 1252"); }El 16/03/2011 19:27, Andrej Mitrovic escribió:Forget it, I'll just use chcp...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
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
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/WindowsApiMmh, the whole winapi just for that seems a little too much. :S
Mar 16 2011
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
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
El 18/03/2011 21:15, Stewart Gordon escribió:On 16/03/2011 22:17, Tom wrote:Thanks! I'll give it a try. Tom;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 21 2011