Parsing a UTF-16LE file line by line, BUG?
pineapple via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 4 11:58:34 PST 2017
On Wednesday, 4 January 2017 at 19:20:31 UTC, Nestor wrote:
> On Wednesday, 4 January 2017 at 18:48:59 UTC, Daniel Kozák
> wrote:
>> Ok, I've done some testing and you are right byLine is broken,
>> so please fill a bug
>
> A bug? I was under the impression that this function was
> *intended* to work only with UTF-8 encoded files.
I'm not sure if this works quite as intended, but I was at least
able to produce a UTF-16 decode error rather than a UTF-8 decode
error by setting the file orientation before reading it.
import std.stdio;
import core.stdc.wchar_ : fwide;
void main(){
auto file = File("UTF-16LE encoded file.txt");
fwide(file.getFP(), 1);
foreach(line; file.byLine){
writeln(file.readln);
}
}
More information about the Digitalmars-d-learn
mailing list