Skip to content
Pure Go TSV Parser
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Makefile
README.md
doc.go
error.go
gtsv.go
gtsv_test.go

README.md

gtsv - Fast TSV Parser written in Go

Build Status Coverage Status Go Report Card GoDoc

Installation

$ go get -u github.com/yagi5/gtsv

Features

  • get values as specific type
  • get row and column numbers which error caused

Usage

Valid TSV case (column numbers of every row are all the same, and type specify is compatible) :

package main

import (
	"bytes"
	"fmt"

	"github.com/yagi5/gtsv"
)

func main() {
  tsv := "1\t2.1\ta\n" +
    "4\t5.2\tb\n" +
    "7\t8.3\tc\n"

  gt := gtsv.New(bytes.NewBufferString(tsv)) // pass io.Reader

  for gt.Next() {
    fmt.Println(gt.Int())
    fmt.Println(gt.Float64())
    fmt.Println(gt.String())
  }
  fmt.Println(gt.Error())
}

Output is:

1
2.1
a
4
5.2
b
7
8.3
c
<nil>

Invalid TSV Case:

func main() {
  tsvInvalid := "1\t2.1\ta\n" +
    "4\t5.2\tb\n" +
    "a\t8.3\tc\n" // first column is not int

  gt := gtsv.New(bytes.NewBufferString(tsvInvalid))

  for gt.Next() {
    fmt.Println(gt.Int())
    fmt.Println(gt.Float64())
    fmt.Println(gt.String())
  }

  if err := gt.Error(); err != nil {
    er := err.(gtsv.Error)
    fmt.Printf("error row: %d, col: %d", er.Row(), er.Col())
	}
}

Output is:

Output: error row: 3, col: 1

For more detail, see godoc.

Lisence

MIT

You can’t perform that action at this time.