Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 16, 2011 Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom | import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001); |
March 16, 2011 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom | 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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom | 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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 Re: Unicode -> Windows 1252 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom | 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. |
Copyright © 1999-2021 by the D Language Foundation