dkh.scanner

  • Declaration

    class Scanner;

    Scanner, not slow, not fast.

    Examples

    1. 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);

    • Declaration

      this(File f);

      f is source file

    • Declaration

      int unsafeRead(T, Args...)(ref T x, auto ref Args args);

      Read tokens. Return the number of success read

    • Declaration

      void read(Args...)(auto ref Args args);

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

    • Declaration

      bool hasNext();

      Do file has next token?