Skip to content

hidetatz/gtsv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Pure Go TSV Parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published