strings

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package strings provides methods for manipulating strings in templates

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bracket

func Bracket(item any) string

Bracket adds brackets around the given string

func BracketWith

func BracketWith(bracketPair string, item any) (string, error)

BracketWith adds brackets of a given type around the given string

func Functions

func Functions() template.FuncMap

Functions that primarily operate on strings

func HasPrefix added in v0.10.2

func HasPrefix(prefix string, subject string) bool

HasPrefix returns true if the supplied string has the given prefix

func HasSuffix added in v0.10.2

func HasSuffix(suffix string, subject string) bool

HasSuffix returns true if the supplied string has the given suffix

func Indent

func Indent(count int, content string) string

Indent prints the given string with the given number of spaces prepended before each line

func Newline

func Newline(count ...int) string

Newline prints a newline (handy for trying to format templates)

func PadLeft

func PadLeft(n int, s any) string

PadLeft prints the given string in the given number of columns, left aligned

func PadRight

func PadRight(n int, s any) string

PadRight prints the given string in the given number of columns, right aligned

func Prefix

func Prefix(prefix string, count int, content string) string

Prefix prints the given string with the given number of 'prefix' prepended before each line

func QuoteBack

func QuoteBack(item any) string

QuoteBack adds back-quotes around the given string

func QuoteDouble

func QuoteDouble(item any) string

QuoteDouble adds double quote around the given string

func QuoteSingle

func QuoteSingle(item any) string

QuoteSingle adds single quote around the given string

func Rep

func Rep(count int, item ...string) string

Rep repeats the given string(s) the given number of times

func Space

func Space(n int) string

Space prints a space character the given number of times

func SplitOn

func SplitOn(glue string, content string) []string

SplitOn creates an array from the given string by separating it by the glue string

func Suffix

func Suffix(suffix string, count int, content string) string

Suffix prints the given string with the given number of 'suffix' appended to each line

func Tab

func Tab(n int) string

Tab prints a tab character the given number of times

func TabIndent

func TabIndent(count int, content string) string

TabIndent prints the given string with the given number of spaces prepended before each line

func TitleCaseWithAbbr

func TitleCaseWithAbbr(abbrev any, word string) (string, error)

TitleCaseWithAbbr upper-cases the first letter of each word, or the whole word if it matches a given abbreviation

func ToColumn

func ToColumn(width int, content string) string

ToColumn formats the given text to not take more than 'w' characters per line, splitting on the space before the word that would take the line over. If no space can be found, the line isn't split (ie words bigger than the line size are printed un-split)

Example

ExampleToColumn

w := 40
s := "Lorem ipsum dolor\nsit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."

got := ToColumn(w, s)

fmt.Println(got)
Output:

Lorem ipsum dolor
sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.

func TrimPrefix added in v0.10.2

func TrimPrefix(prefix string, subject string) string

TrimPrefix removes the given prefix from the supplied string, or does nothing if the string doesn't have the prefix

func TrimSuffix added in v0.10.2

func TrimSuffix(suffix string, subject string) string

TrimSuffix removes the given suffix from the supplied string, or does nothing if the string doesn't have the suffix

func TypeKind

func TypeKind(value any) string

TypeKind returns the "kind" of the given value as a string

func TypeName

func TypeName(value any) string

TypeName returns the type of the given value as a string

func Unindent

func Unindent(count int, content string) (string, error)

Unindent removes up to 'count' spaces from the start of all lines within 'content'

func UppercaseFirst

func UppercaseFirst(s any) string

UppercaseFirst converts the first character in a string to uppercase

Types

This section is empty.

Jump to

Keyboard shortcuts

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