Module dlangui.core.linestream

This module contains text stream reader implementation

Implements class LineStream for reading of unicode text from stream and returning it by lines.

Support utf8, utf16, utf32 be and le encodings, and line endings - according to D language source file specification.

Low resource consuming. Doesn't flood with GC allocations. Dup line if you want to store it somewhere.

Tracks line number.


import dlangui.core.linestream;

import std.stdio;
import std.conv;
import std.utf;
string fname = "somefile.d";
writeln("opening file"); f = new;
scope(exit) { f.close(); }
try {
    LineStream lines = LineStream.create(f, fname);
    for (;;) {
        dchar[] s = lines.readLine();
        if (s is null)
        writeln("line " ~ to!string(lines.line()) ~ ":" ~ toUTF8(s));
    if (lines.errorCode != 0) {
        writeln("Error ", lines.errorCode, " ", lines.errorMessage, " -- at line ", lines.errorLine, " position ", lines.errorPos);
    } else {
        writeln("EOF reached");
} catch (Exception e) {
    writeln("Exception " ~ e.toString);


Name Description
LineStream Support reading of file (or string in memory) by lines
OutputLineStream Text file writer which supports different text file formats


Name Description
TextFileFormat Text file format


Name Description
EncodingType File encoding
LineEnding Line ending style


Vadim Lopatin,


Vadim Lopatin, 2014


Boost License 1.0