October 05, 2007 Re: Displaying non UTF-8 8 bit character codes with writefln() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote: > "Regan Heath" <regan@netmail.co.nz> wrote in message news:fe5d88$15l$1@digitalmars.com... > <snip> >> 1. avoid the valid utf-8 cahracter check. >> 2. make the console display utf-8 correctly. >> >> To achive #1 you've gotta use printf, eg. >> printf("%c\n", 230); > > No I gottan't. I could use putchar, puts or OutputStream.writeString for example. Sure, except the OP wanted formatting. End of the day, as long as you know what you're doing using printf isn't going to kill you. > <snip> >>> This misses the point slightly. The user shouldn't have to change the codepage just to get someone else's application to work properly. >> >> Sadly, if the application is outputting UTF-8 you don't have a choice. > > But how many DOS or Windows console apps in the real world output UTF-8? Everything written in D using writefln from phobos ;) Even if you're only outputting ASCII characters (a subset of UTF-8 - as I'm sure you know) you have the ability to output the full range of UTF-8 codepoints and really we need a console which can handle that. > Presumably not many, considering that no versions of DOS and only a few versions of Windows support it. There's also a causal loop in that even modern Windows versions don't come with the console code page set to 65001 by default. I don't know what is likely to break this loop, but I doubt that the restrictiveness of one language's standard library is going to do it. True. I wonder what the vista console defaults to? Are they still using local code pages or are they using UTF-8 or UTF-16 (perhaps more likely) >>> What you want is my utility library: >>> http://pr.stewartsplace.org.uk/d/sutil/ >> >> Cool. You're converting UTF-8 to the console code page I assume. > > Exactly. (Well, as exactly as is possible under the constraints.) :) Regan |
October 05, 2007 Re: Displaying non UTF-8 8 bit character codes with writefln() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | "Regan Heath" <regan@netmail.co.nz> wrote in message news:fe5g9k$5i6$1@digitalmars.com... <snip> > True. I wonder what the vista console defaults to? Are they still using local code pages or are they using UTF-8 or UTF-16 (perhaps more likely) <snip> Mine defaults to 850. (Strange - British installations of MS-DOS back in the day always default to 437 as far as my experience goes. Sometimes under Win9x, you would get the anomaly of 437 in full screen mode, but a console font in windowed mode that's set up for 850.) But having it use UTF-16 would break far too many programs. There is, however, a function ReadConsoleW, which reads characters in UTF-16 regardless of the active code page. But it doesn't work if stdin is redirected. But I also found that ReadFile doesn't handle UTF-8 console input properly. Look at the way my library uses the two functions, each to get around the problems with the other depending on circumstance. Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit. |
Copyright © 1999-2021 by the D Language Foundation