[Issue 11374] New: Wrong UTF-8 decoding when calling File.readln(buf) with typeof(buf) == string.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 28 15:54:29 PDT 2013
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 at puremagic.com
ReportedBy: joanbrugueram at gmail.com
--- Comment #0 from joanbrugueram at 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: -------
More information about the Digitalmars-d-bugs
mailing list