Module beamui.core.linestream

Line stream reader and writer.

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.

Synopsis

import std.stdio : writeln, writefln;

string filename = "somefile.d";
writeln("opening file");
auto fstream = new FileInputStream(filename);
scope (exit)
    fstream.close();

try
{
    auto lines = LineStream.create(fstream, filename);
    while (true)
    {
        dchar[] s = lines.readLine();
        if (s is null)
            break;
        writefln("line %s: %s", lines.line, s);
    }
    if (lines.errorCode != 0)
    {
        writefln("Error(%s,%s) %s: %s", lines.errorLine, lines.errorPos, lines.errorCode, lines.errorMessage);
    }
    else
    {
        writeln("EOF reached");
    }
}
catch (Exception e)
{
    writeln("Exception " ~ e.toString);
}

Import line

import beamui.core.linestream;

Classes

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

Structs

NameDescription
TextFileFormat Text file format

Enums

NameDescription
EncodingType File encoding
LineEnding Line ending style