Parsing a UTF-16LE file line by line, BUG?

Nestor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 15 07:00:40 PST 2017


On Sunday, 15 January 2017 at 14:48:12 UTC, Nestor wrote:
> After some testing I realized that byLine was not the one 
> failing, but any string manipulation done to the obtained line. 
> Compile the following example with and without -debug and run 
> to see what I mean:
>
> import std.stdio, std.string;
>
> enum
>   EXIT_SUCCESS = 0,
>   EXIT_FAILURE = 1;
>
> int main() {
>   version(Windows) {
>     import core.sys.windows.wincon;
>     SetConsoleOutputCP(65001);
>   }
>   auto f = File("utf16le.txt", "r");
>   foreach (line; f.byLine()) try {
>     string s;
>     debug s = cast(string)strip(line); // this is the one 
> causing problems
>     if (1 > s.length) continue;
>     writeln(s);
>   } catch(Exception e) {
>     writefln("Error. %s\nFile \"%s\", line %s.", e.msg, e.file, 
> e.line);
>     return EXIT_FAILURE;
>   }
>   return EXIT_SUCCESS;
> }

By the way, when caught, the exception says it's in file 
src/phobos/std/utf.d line 1217, but that file only has 784 lines. 
That's quite odd.

(I am compiling with dmd 2.072.2)


More information about the Digitalmars-d-learn mailing list