Switch ignores case (?)

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 23 11:07:49 PST 2016


On Wednesday, 23 November 2016 at 18:34:28 UTC, Steven 
Schveighoffer wrote:

>
> Please file here: https://issues.dlang.org/enter_bug.cgi
>
> I think this has been there forever. Happens in 2.040 too (the 
> earliest dmd I have on my system).
>
> -Steve

Here it is:

https://issues.dlang.org/show_bug.cgi?id=16739

(I think I marked it as "P1" (default option), maybe it's "P2", 
didn't know what to choose)

It has something to do with the smart quote, e.g.:

import std.array;
import std.conv;
import std.stdio;

void main()
{
   auto tokens = to!(dchar[][])(["D"d, "’"d, "Addario"d, "'"d, 
"."d]);
   // Or use this below:
   //~ dstring[] tokens = ["D"d, "’"d, "Addario"d, "'"d];
   while (!tokens.empty)
   {
     switch (tokens[0])
     {
       case "\u2019"d:
         writeln("Apostrophe smart " ~ tokens[0]);
         break;
       case "\u0027"d:
         writeln("Apostrophe straight " ~ tokens[0]);
         break;
       case "D"d:
         writeln("Letter 'D'");
         break;
       case "."d:
         writeln("fullstop " ~ tokens[0]);
         break;
       default:
         writeln("Other " ~ tokens[0]);
         break;
     }
     tokens = tokens[1..$];
   }
}

prints:

Letter 'D'
Other ’  // <== not expected
Other Addario
Apostrophe straight '
fullstop .

Both LDC and DMD produce the same error. I discovered this while 
writing a tokenizer. It is a bit upsetting, because it is really 
an essential thing. The workaround for now would be

if (token[0] == "\u2019"d)
  goto Wherever;

which works, by the way.


More information about the Digitalmars-d-learn mailing list