tabular

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2016 License: Apache-2.0 Imports: 5 Imported by: 14

Documentation

Overview

Package tabular simplifies the reading of tabular data. It is especially intended for use when finding certain values in certain rows or columns, but can be useful for simply handling lists of strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnySatisfies

func AnySatisfies(pred StringPredicate, slice []string) bool

AnySatisfies checks to see whether any string in a given slice satisfies the provided StringPredicate.

func HasNonEmpty added in v0.2.2

func HasNonEmpty(slice []string) bool

HasNonEmpty checks to see if there is a single string with a non-whitespace character in the list

func IndiciesOf added in v0.2.2

func IndiciesOf(needles []string, haystack string) (indicies []int)

IndiciesOf takes a list of needles and a haystack and returns the first locations of all the needles

func Lines added in v0.2.2

func Lines(str string) []string

Lines splits a string on newlines

func ReIn

func ReIn(re *regexp.Regexp, slice []string) bool

ReIn is like StrIn or StrContainedIn, but matches regexps instead.

func SliceEqual added in v0.2.2

func SliceEqual(slc1 []string, slc2 []string) bool

func StrContainedIn

func StrContainedIn(str string, slice []string) bool

StrContainedIn works like strIn, but checks for substring containing rather than whole string equality.

func StrIn

func StrIn(str string, slice []string) bool

StrIn checks to see if a given string is in a slice of strings.

func TableEqual added in v0.2.2

func TableEqual(t1 Table, t2 Table) bool

TableEqual tests the equality of the tables by examining each cell

func ToString added in v0.2.2

func ToString(table Table) string

ToString returns a table ([][]string) as a nicely formatted string

func Unlines added in v0.2.2

func Unlines(slc []string) string

Unlines is the inverse operation of lines

Types

type Column

type Column []string

Column is a slice of strings, a vertical slice of a Table.

func GetColumn

func GetColumn(col int, slice [][]string) (column Column)

GetColumn isolates the entries of a single column from a 2D slice, specified by the column number (counting from zero on the left).

func GetColumnByHeader

func GetColumnByHeader(name string, tab Table) (column Column)

GetColumnByHeader returns the body of a column with a header that is equal to name (ignoring case differences). It is for developer ease and future-proofing, as it doesn't rely on an index.

func GetColumnNoHeader

func GetColumnNoHeader(col int, tab Table) Column

GetColumnNoHeader safely removes the first element from a column.

type Row

type Row []string

Row is one element of a Table, a horizontal slice.

type StringPredicate

type StringPredicate func(str string) bool

StringPredicate is a function that filters a list of strings

type Table

type Table [][]string

Table is a 2D slice of strings, for representing tabular data as cells, in rows and columns.

func ProbabalisticSplit

func ProbabalisticSplit(str string) (output Table)

ProbabalisticSplit splits a string based on the regexp that gives the most consistent line length (potentially discarding one outlier line length).

func SeparateOnAlignment added in v0.2.2

func SeparateOnAlignment(str string) (table Table)

SeparateOnAlignment splits a table based on the indicies of its headers, assuming all columns are left-aligned and all headers are separated by whitespace

func SeparateString

func SeparateString(rowSep *regexp.Regexp, colSep *regexp.Regexp, str string) (output Table)

SeparateString is an abstraction of stringToSlice that takes two kinds of separators, and splits a string into a 2D slice based on those separators

func StringToSlice

func StringToSlice(str string) (output Table)

StringToSlice takes in a string and returns a 2D slice of its output, separated on whitespace and newlines TODO: this should be depreciated by probabalisticSplit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL