[Issue 10453] Allow a hex string as literal for an array of ubytes?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 27 14:21:52 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=10453



--- Comment #1 from Parke <parke.nexus at gmail.com> 2013-11-27 14:21:45 PST ---
Cross posting from D.learn:
http://forum.dlang.org/thread/lnyykrbmfxsljpxezlcm@forum.dlang.org

TDPL, page 37, says:

"Hex strings are useful for defining raw data; the compiler makes 
no attempt whatsoever to interpret the contents as Unicode 
characters or anything else but hexadecimal digits."

But:

static immutable (char[32])  s0 = x"0000";    // compiles
static string                s1 = x"cccc";    // compiles
static immutable (char[])    s2 = x"cccc";    // compiles
static immutable (char[32])  s3 = x"cccc";    // Error: Invalid 
trailing code unit
static immutable (char[32])  s4 = x"cc";      // Error: Truncated 
UTF-8 sequence
static immutable (ubyte[])   s5 = x"cccc";    // Error: cannot 
implicitly convert ...

static immutable (ubyte[32]) s6 = x"cccc";    // Error: Invalid 
trailing code unit
                                              // Error: cannot 
implicitly convert ...

"Invalid trailing code unit" and "Truncated UTF-8 sequence" 
certainly look like Unicode interpretation errors to me.

(Of course, what I would really like to do is initialize a ubyte 
array with a hex string, preferably without a cast.)

I cannot find any relevant documentation on either of these pages.
http://dlang.org/lex.html
http://dlang.org/arrays.html#strings

Any advice would be appreciated.  Thanks!

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list