ByLineFast

Reads by line in an efficient way (10 times faster than File.byLine from std.stdio). This is accomplished by reading entire buffers (fgetc() is not used), and allocating as little as possible.

The char \n is considered as default separator, removing the previous \r if it exists.

The \n is never returned. The \r is not returned if it was part of a \r\n (but it is returned if it was by itself).

The returned string is always a substring of a temporary buffer, that must not be stored. If necessary, you must use str[] or .dup or .idup to copy to another string. DIP-25 return qualifier is used in front() to add extra checks in @safe callers of front().

struct ByLineFast (
Char
Terminator
) {
File file;
char[] line;
bool first_call;
char[] buffer;
char[] strBuffer;
const
string separator;
KeepTerminator keepTerminator;
}

Examples

File f = File("file.txt"); foreach (string line; ByLineFast(f)) { ...process line... //Make a copy: string copy = line[]; }

The file isn't closed when done iterating, unless it was the only reference to the file (same as std.stdio.byLine). (example: ByLineFast(File("file.txt"))).

Meta