tables

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package tables provides functions for dealing with table-like structures, such as used by 2DA or IDS resource types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table contains the necessary information to query or alter table data.

func Load

func Load(r io.Reader) *Table

Load uses the given Reader to load table data from the underlying buffer. The function returns a pointer to the Table object.

This function assumes that input data is encoded in ANSI Windows-1252. Use function Error to check if the Load function returned successfully.

func LoadEx

func LoadEx(r io.Reader, cmap *charmap.Charmap) *Table

LoadEx uses the given Reader to load table data from the underlying buffer, using the specified character map for ANSI decoding.

Specify a nil charmap to skip the decoding operation. The function returns a pointer to the Table object. Use function Error to check if the Load function returned successfully.

func (*Table) ClearError

func (t *Table) ClearError()

ClearError clears the error state from the last Table operation. Must be called for subsequent operations to work correctly.

func (*Table) ClearModified

func (t *Table) ClearModified()

ClearModified explicitly marks the Table object as unmodified.

func (*Table) Columns

func (t *Table) Columns() int

Columns returns the maximum number of columns available for the table. Operation is skipped if error state is set.

func (*Table) DeleteItem

func (t *Table) DeleteItem(row, col, minCols int) string

DeleteItem removes the table item at [row, col] for rows containing minCols or more items and returns the removed item.

As a result the number of columns for this row will decrease by one. Sets t.err if the specified location does not exist. Operation is skipped if error state is set.

func (*Table) DeleteRow

func (t *Table) DeleteRow(rowIndex int)

DeleteRow removes the specified row of data. rowIndex must be in range 0 to Rows(0) exclusive. Operation is skipped if error state is set.

func (*Table) Error

func (t *Table) Error() error

Error returns the error state of the most recent operation on Table. Use ClearError function to clear the current error state.

func (*Table) GetItem

func (t *Table) GetItem(row, col, minCols int) string

GetItem returns the item at [row, col] for rows containing minCols or more items.

Sets t.err and returns empty item if [row, col] doesn't point to a valid location. Operation is skipped if error state is set.

func (*Table) InsertItem

func (t *Table) InsertItem(row, col, minCols int, item string)

InsertItem inserts a new item with the specified string at [row, col] for rows containing minCols or more items.

Sets t.err and skips insertion if location does not exist or item is empty. Operation is skipped if error state is set.

func (*Table) InsertRow

func (t *Table) InsertRow(rowIndex int, items []string)

InsertRow inserts a new table row and fills it with the specified items. No row is inserted if items doesn't contain non-empty items.

rowIndex must be in range 0 to Rows(0) inclusive. Operation is skipped if error state is set.

func (*Table) InsertRowBuffer

func (t *Table) InsertRowBuffer(rowIndex int, buffer []byte)

InsertRowString inserts a new table row and fills it with the items extracted from the given byte array.

No row is inserted if buffer doesn't contain non-empty items. rowIndex must be in range 0 to Rows(0) inclusive. Operation is skipped if error state is set.

func (*Table) InsertRowString

func (t *Table) InsertRowString(rowIndex int, line string)

InsertRowString inserts a new table row and fills it with the items extracted from the given string.

No row is inserted if line doesn't contain non-empty items. rowIndex must be in range 0 to Rows(0) inclusive. Operation is skipped if error state is set.

func (*Table) Is2DA

func (t *Table) Is2DA() bool

Is2DA returns true only if the current content conforms to the 2DA table format. Operation is skipped if error state is set.

func (*Table) IsIDS

func (t *Table) IsIDS() bool

IsIDS returns true only if the current content conforms to the IDS table format. Operation is skipped if error state is set.

func (*Table) IsModified

func (t *Table) IsModified() bool

IsModified returns whether the current table content has been modified by a previous operation. The return value is only provided for informal purposes. None of the Table functions rely on it.

func (*Table) PutItem

func (t *Table) PutItem(row, col, minCols int, item string)

PutItem assigns item to the existing table location [row, col] for rows containing minCols or more items.

Sets t.err if the specified location does not exist or item is empty. Operation is skipped if error state is set. Hint: Use DeleteItem to remove individual items. Use InsertItem to insert a new item.

func (*Table) RowColumns

func (t *Table) RowColumns(row, minCols int) int

RowColumns returns the number of columns of the specified row that has minCols or more items. Returns -1 if row doesn't exist. Operation is skipped if error state is set.

func (*Table) Rows

func (t *Table) Rows(cols int) int

Rows returns the number of rows containing at least "cols" number of columns. Operation is skipped if error state is set.

func (*Table) Save

func (t *Table) Save(w io.Writer, prettify bool)

Save writes the current table content to the specified Writer, encoding text as specified by the Load function.

Does nothing if the Table is in an invalid state (see Error function). Set prettify to ensure that table data is properly aligned.

func (*Table) SaveEx

func (t *Table) SaveEx(w io.Writer, cmap *charmap.Charmap, prettify bool)

SaveEx writes the current table content to the specified Writer, using the specified character map for ANSI encoding.

Specify a nil charmap to skip the encoding operation. Does nothing if the Table is in an invalid state (see Error function). Set prettify to ensure that table data is properly aligned.

Jump to

Keyboard shortcuts

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