Jump to page: 1 2
Thread overview
Unicode -> Windows 1252
Mar 16, 2011
Tom
Mar 16, 2011
Andrej Mitrovic
Mar 16, 2011
Tom
Mar 17, 2011
Tom
Mar 17, 2011
Andrej Mitrovic
Mar 17, 2011
Tom
Mar 16, 2011
Andrej Mitrovic
Mar 16, 2011
Tom
Mar 16, 2011
Andrej Mitrovic
Mar 19, 2011
Stewart Gordon
Mar 22, 2011
Tom
March 16, 2011
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;
March 16, 2011
import std.c.windows.windows;
extern(Windows) BOOL SetConsoleOutputCP(UINT);
SetConsoleOutputCP(65001);
March 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
March 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.
March 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.
March 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/WindowsApi

Mmh, the whole winapi just for that seems a little too much. :S
March 17, 2011
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...
March 17, 2011
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");
}
March 17, 2011
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;
March 19, 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.
« First   ‹ Prev
1 2