[Issue 11068] New: raw formatting of chars and strings is wrong

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 19 00:24:44 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11068

           Summary: raw formatting of chars and strings is wrong
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: monarchdodra at gmail.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-09-19 00:24:40 PDT ---
//----
    foreach(C ; TypeTuple!(char, wchar, dchar))
    {
        auto app = appender!string();
        formattedWrite(app, "[%r] [%r]", cast(C)'a', to!(const(C)[])("aa"));
        writefln("[%(%x, %)]", app.data().representation());
    }
//----

//What I expected
[5b, 61, 5d, 20, 5b, 61, 61, 5d]
[5b, 61, 0, 5d, 20, 5b, 61, 0, 61, 0, 5d]
[5b, 61, 0, 0, 0, 5d, 20, 5b, 61, 0, 0, 0, 61, 0, 0, 0, 5d]

//What I got
[5b, 61, 0, 0, 0, 5d, 20, 5b, 61, 61, 5d]
[5b, 61, 0, 0, 0, 5d, 20, 5b, 61, 61, 5d]
[5b, 61, 5d, 20, 5b, 61, 61, 5d]

//----
    foreach(C ; TypeTuple!(char, wchar, dchar))
    {
        auto app = appender!string();
        formattedWrite(app, "%r", to!(const(C)[])("日本語"));
        writefln("[%(%x, %)]", app.data().representation());
    }
//----

//What I expected
[e6, 97, a5, e6, 9c, ac, e8, aa, 9e] //9 UTF code units
[e5, 65, 2c, 67, 9e, 8a] //3 2-Byte code units
[e5, 65, 0, 0, 2c, 67, 0, 0, 9e, 8a, 0, 0] //3 4 byte code units

//What I got.
[e5, 65, 0, 0, 2c, 67, 0, 0, 9e, 8a, 0, 0]
[e5, 65, 0, 0, 2c, 67, 0, 0, 9e, 8a, 0, 0]
[e5, 65, 0, 0, 2c, 67, 0, 0, 9e, 8a, 0, 0]

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


More information about the Digitalmars-d-bugs mailing list