File: tokenizer.d

package info (click to toggle)
val-and-rick 0.1a.dfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 3,200 kB
  • sloc: xml: 349; makefile: 27
file content (45 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * $Id: tokenizer.d,v 1.1.1.1 2005/03/13 16:15:04 kenta Exp $
 *
 * Copyright 2004 Kenta Cho. Some rights reserved.
 */
module abagames.util.tokenizer;

private import std.stdio;
private import std.string;
private import std.conv;

/**
 * Tokenizer.
 */
public class Tokenizer {
 private:

  public static string[] readFile(string fileName, string separator) {
    string[] result;
    File fd = File(fileName);
    for (;;) {
      string line = fd.readln();
      if (!line)
	break;
      string[] spl = split(line, separator);
      foreach (string s; spl) {
	string r = strip(s);
	if (r.length > 0)
	  result ~= r;
      }
    }
    return result;
  }
}

/**
 * CSV format tokenizer.
 */
public class CSVTokenizer {
 private:

  public static string[] readFile(string fileName) {
    return Tokenizer.readFile(fileName, ",");
  }
}