Scanner

Scanner, not slow, not fast.

Constructors

this
this(File f)

f is source file

Members

Functions

hasNext
bool hasNext()

Do file has next token?

read
void read(Args args)

Read tokens. If can't read, throw exception.

unsafeRead
int unsafeRead(T x, Args args)

Read tokens. Return the number of success read

Examples

import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3])); // array(except char) read whole line
assert(equal(c[], "ab")); // char array(char[], char[2], ...) return token
assert(equal(d, "cde")); // string is char array
assert(e == 1.0);
assert(equal(f, [1.0, 2.0]));
assert(!sc.hasNext);

Meta