Skip to content

greenimpala/golumn

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

golumn

Format delimited data into columns. Similar to the unix shell program column.

Example

Some CSV file:

Date,Type,Description,Amount
30/10/2013,DEB,SUPERMARKET 29833,5.15
29/10/2013,DEB,AMAZON MKPLACE,5.63

Parse the file:

var result = golumn.parse(string(data), ",", golumn.Options{
	MaxColumnWidth: 5,
	Truncate:       true,
})
print(result)

Prints the following:

Date 	Type	Descr	Amoun
 30/1	DEB 	SUPER	5.15 
 29/1	DEB 	AMAZO	5.63 

Usage

Download and compile the source with go get github.com/st3redstripe/golumn. Then import as usual.

import (
	"github.com/st3redstripe/golumn"
)

Call Parse passing in an input string and a delimiter.

func Parse(input string, delim string) string

Use ParseF to override default options.

func ParseF(input string, delim string, options Options) string

Options

For use with ParseF - where options is a golumn.Options struct containing a subset of the following

  • ColumnSpacer string - The characters used to pad columns, default is \t.
  • NewLine string - New line character, default is \n.
  • ColumnWidth int - Sets colums to be a fixed width.
  • MaxColumnWidth int - Constrains column widths. Overidden if a valid ColumnWidth option is given.
  • Truncate bool - Truncates any cells that overflow the ColumnWidth or MaxColumnWidth.

About

Format delimited data into columns

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages