Wrong output of quotes in Windows (encoding?)
Hugo Florentino
hugo at acdam.cu
Wed Dec 18 05:32:41 PST 2013
Hi,
A short while ago I had minor difficulties escaping quotes, and noticed
(I don't remember where) a simple function by a D user which I have now
tried to enhance. The problem is that output is incorrect in Windows
(even with unicode-supporting fonts). I tried to use transcode but could
not get it to work.
Check the following code, and please advise me what to do in order to
get the correct 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 = "just a test";
foreach(char type; a)
writeln(format("Quote type %s:\t%s", type, quote(input, type)));
}
More information about the Digitalmars-d-learn
mailing list