June 08, 2011 [Issue 6125] New: to!string doesn't throw on invalid UTF sequence | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6125 Summary: to!string doesn't throw on invalid UTF sequence Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-06-08 11:41:02 PDT --- I'm not sure if this is a bug or wanted behavior: auto x = to!string(cast(char)255); That won't throw. But this will: auto x = to!string(cast(char)255); // or try 128 auto z = toUTF8(x); // throws I've had this example code translated from C: foreach (y; 0 .. 16) foreach (x; 0 .. 16) { auto buffer = to!string(cast(char)(16 * x + y)); auto result = buffer.toUTF16z; // call to utf16z for the winapi } Essentially the code builds a table of characters that it prints out. But it doesn't seem to take into account invalid UTF8 code points. This leads me to another question, how does one iterate through valid UTF code points, starting from 0? Is there a Phobos function that does that? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation