String Literal Docs

Ellery Newcomer ellery-newcomer at utulsa.edu
Sat Jun 19 15:17:25 PDT 2010


On 06/19/2010 04:26 PM, div0 wrote:
> On 19/06/2010 22:16, Ellery Newcomer wrote:
>> On 06/19/2010 03:12 PM, Alix Pexton wrote:
>>> I've been sketching some grammar diagrams for D2.0, a little like those
>>> on JSON.org, and of course I didn't get far before I ran into something
>>> odd.
>>>
>>> In the section of www.digitalmars.com/d/2.0/lex.html on string literals,
>>> the productions imply that the [c|w|d] "postfix" is allowed on Wysiwyg,
>>> DoubleQuote and Hex strings and not on either Delimited or Token
>>> strings, which didn't make a lot of sense to me, so I tested it with DMD
>>> (v2.046, win)...
>>>
>>> ---
>>>
>>> import std.stdio;
>>>
>>> void main(){
>>> auto t1 = "double quote"d; // OK
>>> auto t2 = `back tick`d; // OK
>>> auto t3 = x"dead beef"; // postfix not allowed on hexstrings!
>>> auto t4 = q"<delimited/>"d;// OK
>>> auto t5 = q{if}d; // OK
>>>
>>> writefln("all literals A-OK!");
>>> }
>>>
>>> ---
>>>
>>> This makes sense to me, HexStrings with wide chars would have made my
>>> brain scream ><
>>
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=4351
>>
>>
>> but I'm not so sure about the hex string one. I think you just gave it
>> invalid unicode. E.g., this compiles fine:
>
> Hex strings are specifically exempted from the requirement for valid utf.
>
>

All I can say is

auto w = x"dead beef"w;

results in

Error: invalid UTF-8 sequence

on dmd 2.047


More information about the Digitalmars-d mailing list