Chinese characters in a string(GDC)

Aziz K. aziz.kerim at gmail.com
Tue May 15 09:04:14 PDT 2007


Roberto Mariottini wrote:
> The problem is that the current D console API doesn't translate form  
> internal Unicode representation to the codepage currently selected in  
> your console.

It doesn't need to convert to the codepage set in the console. There is a  
neat function called WriteConsoleW() which can print any Unicode character  
to the console regardless of the current codepage. Other than that there  
is the issue with the command line, because the arguments aren't passed as  
Unicode to the main function. To remedy that problem I've written a  
function that takes the command line with GetCommandLineW() and parses it  
into an array of wchar[]s (applying the weird escaping rules cmd.exe  
uses.) I've only used calloc and realloc so that the function can be used  
while the garbage collector hasn't been initialized yet. I'll submit the  
function to bugzilla when I've finished it. At first I'd like to see it in  
Phobos for a while, just in case some bugs crop up, and if it has stood  
the test of time then Walter could move it to dmain2.d so that every D  
application has proper support for Unicode command line arguments by  
default :-)

Apart from these problems another one comes to mind, which is, that the  
font set in the console has to support the codepoints you want to print,  
otherwise you will get only small boxes. I don't know how to change to  
another true type font other than Luicida Sans Console (because the dialog  
restricts you to only two fonts), but as far as I can remember, there  
should be a guide out there explaining how to do it.

PS.: Go to http://openquran.googlecode.com/svn/trunk/src/main.d if you  
want to see how I'm using WriteConsoleW in the Windows version of my  
program.

> This makes D console programs currently unusable for any language other  
> than English.

Yes, but fortunately not any longer.

Regards.



More information about the Digitalmars-d mailing list