Documentation ¶
Index ¶
- func Cut(s string, sz int) (chunks []string)
- func LazyCut(s string, sz int) (chunks []string)
- func PadCenter(s []byte, sz int) []byte
- func PadLeft(s []byte, sz int) []byte
- func PadRight(s []byte, sz int) []byte
- func Repeat(s string, sz int) string
- func Runewidth(c rune) int
- func Stringwidth(s string) int
- func TrimLeadingSpace(s []byte) []byte
- func TrimSpace(s []byte) []byte
- func TrimSuffix(s []byte, r rune) []byte
- func TrimTrailingSpace(s []byte) []byte
- func Truncate(s string, limit int) string
- func Width(p []byte) (w int)
- type Cutter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cut ¶
Cut cuts a string at end-of-line if the line "visual" length is shorter than the given limit or at word boundary (space) to stay as close as possible under the given limit. Should a word exists that is longer than the limit, the word is split in pieces. If provided limit is zero or less than zero, Cut only acts at end-of-line.
func LazyCut ¶ added in v0.6.1
LazyCut cuts a string at end-of-line if the line "visual" length is shorter than the given limit or at word boundary (space) to stay as close as possible under the given limit. Should a word exists that is longer than the limit, the word is not split to fit into the given limit ans is kept as is. If provided limit is zero or less than zero, Cut only acts at end-of-line.
func PadCenter ¶
PadCenter equally prefixes and complete a slice of bytes with spaces until its "visual" size reaches the provided limit.
func PadLeft ¶
PadLeft prefixes a slice of bytes with spaces until its "visual" size reaches the provided limit.
func PadRight ¶
PadRight completes a slice of bytes with spaces until its "visual" size reaches the provided limit.
func Stringwidth ¶ added in v0.7.0
Stringwidth returns the "visual" width of string.
func TrimLeadingSpace ¶ added in v0.7.0
TrimLeadingSpace trims any leading space (as defined by Unicode) from a slice of bytes.
func TrimSpace ¶
TrimSpace trims any leading and trailing space (as defined by Unicode) from a slice of bytes.
func TrimTrailingSpace ¶ added in v0.7.0
TrimTrailingSpace trims any trailing space (as defined by Unicode) from a slice of bytes.
Types ¶
type Cutter ¶ added in v0.7.0
type Cutter struct { // Maxwidth is the maximum line's "visual" length at which the Cutter // force a split. Maxwidth int // Lazycut flag governs the Cutter's behavior in case a word is // encountered whose "visual" length is longer than Cutter's MaxWidth. // When true, the word is kept as is, if false, the word is cut in // place. Lazycut bool // WordBoundaries list the byte considered as word boundaries where a // Cutter can split a line. WordBoundaries []byte }
Cutter cuts a slice of bytes at end-of-line if the line's "visual" length is shorter than the maximum line limit or at word boundary to stay as close as possible under the maximum limit. Should a word exist that is longer than the limit, the word is either split in chunk or kept as is depending on Lazycut flag.
func NewLazyCutter ¶ added in v0.7.0
NewLazyCutter creates a new Cutter that lazily manage word longer than maxwidth.
func (Cutter) Split ¶ added in v0.7.0
Split cuts s at the first encountered end-of-line or at the word boundary at which the "visual" width is as close as possible (but lower than) Cutter max width. Split returns the two parts of the operation's result. Should no end-of-line nor the "visual" width be reached, result will be nil, s.