コード例 #1
0
ファイル: data_provider.go プロジェクト: victor-fong/ginson
func (dp CSVDataProvider) dataChannel() <-chan *Track {
	result := make(chan *Track, 10)

	var reader io.ReadSeeker = createReader(dp.file_path)
	var scanner *reverse.Scanner = reverse.NewScanner(reader)

	var symbol string = getSymbolFromPath(dp.file_path)

	go func() {
		for scanner.Scan() {
			var text string = scanner.Text()

			var split_text []string = strings.Split(text, ",")
			if split_text[0] != "Date" {
				var track *Track = &Track{
					symbol: symbol,
					date:   parseTime(split_text[0]),
					open:   parseFloat32(split_text[1]),
					high:   parseFloat32(split_text[2]),
					low:    parseFloat32(split_text[3]),
					end:    parseFloat32(split_text[4]),
					volume: parseUint64(split_text[5]),
				}

				result <- track
			}
		}
		close(result)
	}()

	return result
}
コード例 #2
0
func main() {
	const input = "Now is the winter of our discontent,\nMade glorious summer by this sun of York.\n"
	scanner := reverse.NewScanner(strings.NewReader(input))
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}
}
コード例 #3
0
ファイル: scan_test.go プロジェクト: juanman2/dot-emacs
func TestScan(t *testing.T) {
	for i, test := range scanTests {
		t.Logf("test %d", i)
		b := reverse.NewScanner(strings.NewReader(test.text))
		b.SetBufSize(10)
		b.Split(test.split)
		var got []string
		for b.Scan() {
			got = append(got, b.Text())
		}
		if b.Err() != nil {
			t.Fatalf("error after scan: %v", b.Err())
		}
		if !reflect.DeepEqual(got, test.tokens) {
			t.Fatalf("token mismatch; got %q want %q", got, test.tokens)
		}
	}
}