Wrong output of quotes in Windows (encoding?)
Ali Çehreli
acehreli at yahoo.com
Wed Dec 18 10:05:49 PST 2013
On 12/18/2013 05:32 AM, Hugo Florentino wrote:
> output is incorrect in Windows (even with unicode-supporting
> fonts).
Is the code page also set to UTF-8? I think you must issue the command
'chcp 65001'.
I have changed your program to print the code units individually in hex.
I changed the test string to a single space character so that you can
identify it easily on the output:
import std.stdio, std.string, std.encoding;
@trusted string quote(in string str, in char chr = 'd') pure {
switch(chr) {
case 'b': return '`' ~ str ~ '`'; // backtick
case 'd': return `"` ~ str ~ `"`; // double
case 'f': return `«` ~ str ~ `»`; // french
case 's': return `'` ~ str ~ `'`; // single
case 't': return `“` ~ str ~ `”`; // typographic
default: return `"` ~ str ~ `"`; // double
}
}
void main() {
char[] a = ['b', 'd', 'f', 's', 't'];
auto input = " ";
foreach(char type; a)
writeln(format("Quote type %s:\t%(%02x %)", type,
cast(ubyte[])quote(input, type)));
}
Does the output of the program look correct according to UTF-8? Then
your compiler has produced a correct program. :) Here is the output I
get on SL6.1 compiled with dmd v2.065-devel-41ebb59:
Quote type b: 60 20 60
Quote type d: 22 20 22
Quote type f: c2 ab 20 c2 bb
Quote type s: 27 20 27
Quote type t: e2 80 9c 20 e2 80 9d
I trust the correctness of this feature of D so much that I am too lazy
to check whether those code units correspond to the intended Unicode
characters. :)
Ali
More information about the Digitalmars-d-learn
mailing list