row

package
v0.4.18 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Data Encoding and Decoding entails the protection of data characters from corruption after being rendered as a PSV table, and restoring the original data from a PSV table.

Encoding

  • leading and trailing spaces need to be escaped
  • '|' needs to be escaped
  • '\' needs to be escaped
  • <tab> needs to be replaced with '\t'
  • fields need to be encoded separately, in order to calculate the correct column widths
  • encoding is only done on raw data (i.e. individual fields)
  • field padding (column alignment) only takes place on encoded fields
  • after encoding and padding, rows need to be joined as an extra step

Decoding

  • un-escaped '|' starts a new field
  • leading and trailing _escaped spaces_ need to be preserved
  • leading and trailing _unescaped spaces_ need to be trimmed
  • (don't use strings.TrimSpace)
  • '\t' needs to be replaced with <tab>
  • '\|' needs to be replaced with '|'
  • '\\' needs to be replaced with '\'
  • decoding always implies splitting and trimming

Index

Constants

View Source
const (
	PIPE = '|'
	ESC  = '\\'
)

Variables

View Source
var ErrNotARow = errors.New("not a table row")

Functions

func Split

func Split(input string) ([]string, error)

State Machine:

Note:

  • input starts with the first character after the initial '|' at the start of the table row.

    | state | character | token | next state | | ---------- | ----------- | -------------- | ---------- | | start | | row_start | pad_left | | ---------- | ----------- | -------------- | ---------- | | pad_left | whitespace | | pad_left | | | escape | field_data | escaped | | | end of line | field_finished | final | | | {any} | field_data | field_data | | ---------- | ----------- | -------------- | ---------- | | escaped | end of line | field_finished | final | | | {any} | field_data | field_data | | ---------- | ----------- | -------------- | ---------- | | field_data | whitespace | | pad_right | | | escape | field_data | escaped | | | pipe | field_start | field_data | | | end of line | field_finished | final | | | {any} | | field_data | | ---------- | ----------- | -------------- | ---------- | | pad_right | whitespace | trailing_data | pad_right | | | escape | field_data | escaped | | | end of line | field_finished | final | | | {any} | field_data | field_data | | ---------- | ----------- | -------------- | ---------- | | final | | row_finished | |

See also row.Join

Types

type Row

type Row[T any] struct {
	Fields []T
	Index  *column.Index
}

Row represents a row of data within a table.

Row is a generic container. At the moment it is used in two contexts: - as a container for returning string data from a table's Strings attribute - for holding [export.Field] structs during table generation

func (Row[T]) Field

func (r Row[T]) Field(name string) (f T)

Field returns the value of row's field, indexed by the column name.

"" is returned if an unknown column name is provided, or if the row does not have enough fields.

func (Row[T]) FieldAt

func (r Row[T]) FieldAt(pos int) (f T)

FieldAt returns the n'th field of a row.

An empty field is returned if the column number provided lies beyond the size of the row.

Jump to

Keyboard shortcuts

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