codegen

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTabSize = 4

DefaultTabSize is used to when calculating line indentation.

Variables

This section is empty.

Functions

func ByteCountInString

func ByteCountInString(s string) int

ByteCountInString returns the length of string in bytes.

func PadWithBytes

func PadWithBytes(s string, c byte, nleft, nright int) string

PadWithBytes adds n of c bytes to the end of the string.

func RepeatByte

func RepeatByte(c byte, n int) []byte

RepeatByte produces a byte slice filled with the specified value.

func TrimRight

func TrimRight(row []string) []string

TrimRight removes empty cells from the end of the row.

Types

type Fragments

type Fragments []*fragment

Fragments is a collection of string fragments.

func Fragmentize

func Fragmentize(intf interface{}) Fragments

func FragmentizeMultiLine

func FragmentizeMultiLine(str string) Fragments

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

func FragmentizeStr(str string) Fragments

FragmentizeStr converts a string into fragments. Detects line breaks and leading white space. Trailing white space is preserved.

func JoinFragments

func JoinFragments(items interface{}, separator string) Fragments

JoinFragments concatenates multiple fragments into a single fragment sequence. The separator sequence is placed in between.

func (Fragments) CommonIndent

func (ff Fragments) CommonIndent() int

CommonIndent calculates common line-start indentation.

func (Fragments) Merge

func (ff Fragments) Merge(tabsize int) string

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

func GridWrapN(segments []string, ncolumns int) Grid

GridWrapN wraps string segments into a grid that contains the specified number of columns.

func (*Grid) Append

func (g *Grid) Append(cells ...string)

Append adds a new row to the end of the grid.

func (Grid) Collapse

func (g Grid) Collapse(colsep string) (lines []string)

Collapse collapses all the rows into strings.

func (Grid) ColumnByteWidth

func (g Grid) ColumnByteWidth(colindex int) int

ColumnByteWidth calculates column width in bytes, returns -1 if the column does not exist

func (Grid) ColumnByteWidths

func (g Grid) ColumnByteWidths() []int

ColumnByteWidths calculates column widths in bytes.

func (Grid) ColumnRuneWidth

func (g Grid) ColumnRuneWidth(colindex int) int

ColumnRuneWidth calculates column width in runes, returns -1 if the column does not exist

func (Grid) ColumnRuneWidths

func (g Grid) ColumnRuneWidths() []int

ColumnRuneWidths calculates column widths in runes.

func (Grid) ColumnWidth

func (g Grid) ColumnWidth(colindex int, f func(string) int) int

ColumnWidth calculates column width, returns -1 if the column does not exist

func (Grid) ColumnWidths

func (g Grid) ColumnWidths(f func(s string) int) []int

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) Insert

func (g *Grid) Insert(beforerow int, cells ...string)

func (Grid) ProcessAll

func (g Grid) ProcessAll(cellfunc func(s string) string)

ProcessAll modifies the content of each cell in the grid.

func (Grid) ProcessColumn

func (g Grid) ProcessColumn(colindex int, cellfunc func(string) string)

ProcessColumn modifies the content of each cell in the specified row.

func (Grid) TrimRows

func (g Grid) TrimRows()

TrimRows removes empty cells at the end of each row.

type Itemizer

type Itemizer struct {
	Pre  string
	Sep  string
	Fmt  string
	Post string
}

func (Itemizer) Itemize

func (z Itemizer) Itemize(items interface{}) Fragments

type StringFilter

type StringFilter func(string) string

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 NewTemplate(s string) Template

func NewTemplet

func NewTemplet(s string) Template

func (Template) Filter

func (t Template) Filter(arg Fragments) Fragments

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

func (Template) Replace

func (t Template) Replace(bindings map[string]interface{}) Fragments

Replace returns a sequence of fragments that is constructed from the content of a template by replacing identifiers and @{IDENT} tags with matching sequences from the bindings map.

Jump to

Keyboard shortcuts

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