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)));
}

Reply via email to