www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11374] New: Wrong UTF-8 decoding when calling File.readln(buf) with typeof(buf) == string.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11374

           Summary: Wrong UTF-8 decoding when calling File.readln(buf)
                    with typeof(buf) == string.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: joanbrugueram gmail.com


--- Comment #0 from joanbrugueram gmail.com 2013-10-28 15:54:27 PDT ---
I'm sorry if this is not really a bug but just some ultra-obscure quirk.

Anyway, doing something like:

    string buf;
    stdin.readln(buf);

Appears to work, but seems to decode some characters wrong (consistently).
Using "char[] buf;" or "stdin.readln()" both work.

Here's a more complete test case:

***************************************************************

import std.stdio;

void main()
{
    ubyte[] weirdcharacterbytes = [0xf0, 0x90, 0xa4, 0x80];
    string weirdcharacter = cast(string)weirdcharacterbytes;

    {
        auto f = File("weirdcharacter.txt", "wb");
        f.rawWrite(weirdcharacterbytes);
    }

    {
        auto f = File("weirdcharacter.txt", "r");
        string s = f.readln();
        writeln(s == weirdcharacter ? "PASS" : "FAIL");
    }

    {
        auto f = File("weirdcharacter.txt", "r");
        char[] s;
        f.readln(s);
        writeln(s == weirdcharacter ? "PASS" : "FAIL");
    }

    {
        auto f = File("weirdcharacter.txt", "r");
        string s;
        f.readln(s);
        writeln(s == weirdcharacter ? "PASS" : "FAIL");
    }
}

***************************************************************

PASS
PASS
FAIL

***************************************************************

Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 28 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11374


Martin Krejcirik <mk krej.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mk krej.cz


--- Comment #1 from Martin Krejcirik <mk krej.cz> 2013-10-29 00:40:27 CET ---
Your example doesn't compile in the git-head. See bug 10517.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11374



--- Comment #2 from joanbrugueram gmail.com 2013-10-29 15:59:32 PDT ---
(In reply to comment #1)
 Your example doesn't compile in the git-head. See bug 10517.
Thank you, it appears that this bug has indeed been fixed. Also, this may sound like a rant or blaming someone else, and it very likely is, but the fact that the source link in the Phobos 2.063.2 documentation points to the prerelease version didn't help (obvious in hindsight, but no wonder I couldn't figure out which overload was being called and gave up). Also, I did indeed run a bugzilla search for 'readln', but the default filter doesn't display closed bugs, so I also couldn't find the closed bug you linked. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 29 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11374


Martin Krejcirik <mk krej.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #3 from Martin Krejcirik <mk krej.cz> 2013-10-30 23:44:43 CET ---
*** This issue has been marked as a duplicate of issue 10517 ***

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