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 ¶
const ( PIPE = '|' ESC = '\\' )
Variables ¶
var ErrNotARow = errors.New("not a table row")
Functions ¶
func Split ¶
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 ¶
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