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

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 16 06:47:23 PST 2017


On Sunday, 15 January 2017 at 19:48:04 UTC, Nestor wrote:
> I see. So correcting my original doubt:
>
> How could I parse an UTF16LE file line by line (producing a 
> proper string in each iteration) without loading the entire 
> file into memory?

Could... roll your own? Although if you wanted it to be UTF-8 
output instead would require a second pass or better yet changing 
how the i iterated.

char[] getLine16LE(File inp = stdin) {
     static char[1024*4] buffer;  //4k reusable buffer, NOT thread 
safe
     int i;
     while(inp.rawRead(buffer[i .. i+2]) != null) {
         if (buffer[i] == '\n')
             break;

         i+=2;
     }

     return buffer[0 .. i];
}


More information about the Digitalmars-d-learn mailing list