Documentation
¶
Index ¶
- Constants
- func ByteCountInString(s string) int
- func PadWithBytes(s string, c byte, nleft, nright int) string
- func RepeatByte(c byte, n int) []byte
- func TrimRight(row []string) []string
- type Fragments
- type Grid
- func (g *Grid) Append(cells ...string)
- func (g Grid) Collapse(colsep string) (lines []string)
- func (g Grid) ColumnByteWidth(colindex int) int
- func (g Grid) ColumnByteWidths() []int
- func (g Grid) ColumnRuneWidth(colindex int) int
- func (g Grid) ColumnRuneWidths() []int
- func (g Grid) ColumnWidth(colindex int, f func(string) int) int
- func (g Grid) ColumnWidths(f func(s string) int) []int
- func (g Grid) Columnize()
- func (g *Grid) Insert(beforerow int, cells ...string)
- func (g Grid) ProcessAll(cellfunc func(s string) string)
- func (g Grid) ProcessColumn(colindex int, cellfunc func(string) string)
- func (g Grid) TrimRows()
- type Itemizer
- type StringFilter
- type Template
Constants ¶
const DefaultTabSize = 4
DefaultTabSize is used to when calculating line indentation.
Variables ¶
This section is empty.
Functions ¶
func ByteCountInString ¶
ByteCountInString returns the length of string in bytes.
func PadWithBytes ¶
PadWithBytes adds n of c bytes to the end of the string.
func RepeatByte ¶
RepeatByte produces a byte slice filled with the specified value.
Types ¶
type Fragments ¶
type Fragments []*fragment
Fragments is a collection of string fragments.
func Fragmentize ¶
func Fragmentize(intf interface{}) Fragments
func FragmentizeMultiLine ¶
FragmentizeMultiLine converts a string into fragments. Detects line breaks and leading white space. Trailing white space is removed. Empty lines at the beginning and at the end are removed.
func FragmentizeStr ¶
FragmentizeStr converts a string into fragments. Detects line breaks and leading white space. Trailing white space is preserved.
func JoinFragments ¶
JoinFragments concatenates multiple fragments into a single fragment sequence. The separator sequence is placed in between.
func (Fragments) CommonIndent ¶
CommonIndent calculates common line-start indentation.
func (Fragments) Merge ¶
Merge produces a string from the fragments. All the line break counters embedded into fragments are expanded into '\n' sequences. Similarly, the leading line indents are expanded into space characters. If the tabsize parameter is greater than zero, the leading line indentation is performed with tabs.
func (Fragments) RemoveCommonIndent ¶
func (ff Fragments) RemoveCommonIndent()
RemoveCommonIndent removes common indentation from all the lines.
type Grid ¶
type Grid [][]string
Grid is a colection of cells arranged into rows.
func GridWrapN ¶
GridWrapN wraps string segments into a grid that contains the specified number of columns.
func (Grid) ColumnByteWidth ¶
ColumnByteWidth calculates column width in bytes, returns -1 if the column does not exist
func (Grid) ColumnByteWidths ¶
ColumnByteWidths calculates column widths in bytes.
func (Grid) ColumnRuneWidth ¶
ColumnRuneWidth calculates column width in runes, returns -1 if the column does not exist
func (Grid) ColumnRuneWidths ¶
ColumnRuneWidths calculates column widths in runes.
func (Grid) ColumnWidth ¶
ColumnWidth calculates column width, returns -1 if the column does not exist
func (Grid) ColumnWidths ¶
ColumnWidths calculates column widths.
func (Grid) Columnize ¶
func (g Grid) Columnize()
Columnize aligns all cells into columns. Cells with rune widths narrower than their column width are right-padded with spaces.
func (Grid) ProcessAll ¶
ProcessAll modifies the content of each cell in the grid.
func (Grid) ProcessColumn ¶
ProcessColumn modifies the content of each cell in the specified row.
type StringFilter ¶
StringFilter is a simple string->string processor.
func StringFormatter ¶
func StringFormatter(f string) StringFilter
func (StringFilter) ProcessStrings ¶
func (f StringFilter) ProcessStrings(ss []string) []string
ProcessStrings returns a slice of strings where each element is modified from the original with the provided function.
type Template ¶
type Template []*token
func NewTemplate ¶
func NewTemplet ¶
func (Template) Filter ¶
Filter returns a sequence of fragments that is constructed from the content of a template where each occurence of '@' is replaced with fragments provided in the arg parameter.
Escaped "\@" sequences are replaced with '@'. If arg is empty, returns empty fragment slice. If template is empty, returns arg.
Example:
t := NewTemplate("Hello, @!") t.Filter(Split("World")) // produces "Hello, World!" t.Filter(nil) // produces empty string