Documentation
¶
Index ¶
- Variables
- func AddLastSpace(value string) (modified string)
- func AppendWithSpace(src, add string) (combined string)
- func BookendRunes(input string) (start, end rune, ok bool)
- func Carve(src, start, end string) (before, middle, after string, found bool)
- func CollapseSpaces(input string) (collapsed string)
- func Empty(value string) (empty bool)
- func EscapeHtmlAttribute(unescaped string) (escaped string)
- func FirstName(fullName string) (firstName string)
- func GetBasicMime(mime string) (basic string)
- func IsAnyQuote[V uint8 | rune](runes ...V) (quote bool)
- func IsFalse(text string) booldeprecated
- func IsFancyQuote[V uint8 | rune](runes ...V) (quote bool)
- func IsLastSpace(value string) (space, ok bool)
- func IsQuote[V uint8 | rune](runes ...V) (quote bool)
- func IsQuoted(maybeQuoted string) (quoted bool)
- func IsQuotedFancy(maybeQuoted string) (start, end rune, quoted bool)
- func IsSpaceOrPunct[T rune | byte](value T) (is bool)
- func IsTrue(text string) booldeprecated
- func LastName(fullName string) (lastName string)
- func NameFromEmail(email string) (name string)
- func ParseDomainName(input string) (tld, name string, subdomains []string)
- func PathToSnake(path string) (snake string)
- func PruneSet(source string, runes ...rune) (pruned string)
- func PruneSpaces(input string) (pruned string)
- func PruneTmplActions(value string) (clean string)
- func QuoteJsonValue(value string) (out string)
- func Scan(src, sep string) (before, after string, found bool)
- func ScanBothCarve(src, start, end string) (before, middle, after string, found bool)
- func ScanCarve(src, start, end string) (before, middle, after string, found bool)
- func ScanLine(source string, line int) (text string, ok bool)
- func ScanQuote(src string) (before, quoted, after string, found bool)
- func SortedByLastName(fullNames []string) (sorted []string)
- func SplitSortReversed(input, separator string) (split []string)
- func ToDeepKey(text string) (deepKey string)
- func ToDeepVar(text string) (deepVar string)
- func ToKebabs(inputs ...string) (out []string)
- func ToLowers(in ...string) (out []string)
- func ToSpaced(text string) (spaced string)
- func ToSpacedCamel(text string) (spacedCamel string)
- func ToSpacedTitle(text string) (spacedTitle string)
- func ToTitleWords(text string) (capitalized string)
- func TrimPrefixes(value string, prefixes ...string) (trimmed string)
- func TrimQuotes(maybeQuoted string) (unquoted string)
- func TrimTmplVar(name string) (trimmed string)
- func UniqueFromSpaceSep(value string, original []string) (updated []string)
- type ByteBuffer
- type QuotePair
- type SortByLength
Constants ¶
This section is empty.
Variables ¶
var (
FancyQuotes = []QuotePair{
{Start: '“', End: '”'},
{Start: '‘', End: '’'},
{Start: '‹', End: '›'},
{Start: '«', End: '»'},
{Start: '»', End: '«'},
{Start: '„', End: '“'},
{Start: '„', End: '”'},
{Start: '「', End: '」'},
{Start: '『', End: '』'},
}
)
Functions ¶
func AddLastSpace ¶ added in v1.1.0
AddLastSpace will add a space to value if value is non-empty and the last rune in value is not unicode.IsSpace
func AppendWithSpace ¶
AppendWithSpace appends add to src with a space, ensuring that only one space is separating the two given strings. If the add string starts with punctuation, no space is used.
AppendWithSpace is intended to be used within the Go-Enjin page format features that need to join text with html constructs. The `.njn` block format for example joins strings and json objects describing html elements into the rendered output.
Enjin Block Example:
{ "type": "p", "text": [ "This sentence ends with a", { "type": "a", "href": "https://go-enjin.org", "text": "link" }, "." ] }
Is rendered without a space between the "link" and the "." but does have a space after the first sentence text.
func BookendRunes ¶ added in v1.3.0
BookendRunes returns the first and last runes of the string, with `ok` being true when there is more than one rune in the input string
func Carve ¶ added in v1.4.0
Carve finds the `start` and `end` markers in `src` and carves out the "before carve", "middle of start/end range" and "after carve" segments. If the `start` and `end` range is not `found` then the `before` will contain the entire `src` input
Carve is based on two calls to strings.Cut, one for the `start` and again for the `end`
func CollapseSpaces ¶ added in v1.8.0
CollapseSpaces returns the input string with all consecutive space characters collapsed to just one space character (tabs are not considered spaces)
func EscapeHtmlAttribute ¶
EscapeHtmlAttribute trims any matching outer quotations (single or double), replaces all double-quotes with `"` and returns the result
func GetBasicMime ¶
GetBasicMime removes the semicolon and any trailing bits from the given mime string
func IsAnyQuote ¶ added in v1.3.0
IsAnyQuote returns true if all `runes` given match IsQuote or IsFancyQuote
func IsFancyQuote ¶ added in v1.3.0
IsFancyQuote returns true if all `runes` given match IsFancyQuote
func IsLastSpace ¶ added in v1.1.0
IsLastSpace returns ok=true if the string has a length greater than zero and space=true if the last rune is unicode.IsSpace
func IsQuote ¶ added in v1.3.0
IsQuote returns true if all `runes` given are one of double-quote ("), single-quote (') or backtick (`)
func IsQuoted ¶
IsQuoted returns true if the first and last characters in the input are the same and are one of the three main quote types: single ('), double (") and literal (`)
func IsQuotedFancy ¶ added in v1.2.0
IsQuotedFancy finds the starting and ending runes, returning true if they match any of the following pairs of quotations:
func IsSpaceOrPunct ¶ added in v1.1.0
IsSpaceOrPunct returns true if the value given is either unicode.IsSpace or unicode.IsPunct
func NameFromEmail ¶
NameFromEmail returns a user's default name based on just their email address, intended to be used as an interesting placeholder on a text input field for the user to supply something better
func ParseDomainName ¶
ParseDomainName returns the given name split into is component parts, in reverse order
func PathToSnake ¶
PathToSnake trims any leading and trailing slashes and converts the string to a snake_cased__directory_separated format where the directory separator is two underscores
func PruneSpaces ¶ added in v1.7.0
PruneSpaces returns the input string without any space characters as defined by unicode.IsSpace
func PruneTmplActions ¶ added in v1.1.0
PruneTmplActions removes all go template action statements
Note that this does not remove the content between if, else and end statements. For example:
`{{ if ... }}stuff{{ else }}moar stuff{{ end }}.`
Turns into:
`stuff moar stuff.` ^ |
Also note that PruneTmplActions takes care to not concatenate non-space text when pruning surrounding actions though will allow punctuation, similarly to AppendWithSpace.
func QuoteJsonValue ¶
QuoteJsonValue is intended to be used when marshalling json content and is applied to only the json values as strings
func ScanBothCarve ¶ added in v1.6.0
ScanBothCarve is like ScanCarve except that ScanBothCarve uses Scan to find both the `start` and `end` separators
func ScanCarve ¶ added in v1.5.0
ScanCarve is like Carve except that ScanCarve uses Scan instead of strings.Cut for finding the `end` separator
func ScanLine ¶ added in v1.7.0
ScanLine searches for newline characters, counting up to the desired line number and returns just the text for that line. The line number starts at one, not zero
func ScanQuote ¶ added in v1.6.0
ScanQuote looks for the first single, double or backtick quoted text, returning the `before`, `quoted` and `after` strings if `found`. Note that the `quoted` string is unquoted (and unescaped). Use strconv.Quote to restore double-quoting
func SortedByLastName ¶
SortedByLastName returns a natual-sorted list of the full names given
func SplitSortReversed ¶
SplitSortReversed is a wrapper around strings.Split and reverses the order of the results
func ToDeepKey ¶
ToDeepKey converts go template variables like `.ThisThing.Variable` to a map key used in like `.this-thing.variable`
func ToDeepVar ¶
ToDeepVar is the opposite of ToDeepKey, translating `.this-thing.variable` to `.ThisThing.Variable` format
func ToSpacedCamel ¶
ToSpacedCamel is a wrapper around ToSpaced and strcase.ToCamel for each word. The difference between ToSpacedTitle and ToSpacedCamel is in what is considered a capital letter. ToSpacedTitle uses unicode.ToTitle to figure that out while ToSpacedCamel uses strcase.ToCamel for that
func ToSpacedTitle ¶
ToSpacedTitle is a wrapper around ToSpaced and ToTitleWords
func ToTitleWords ¶
ToTitleWords title-cases all words in the given text
func TrimPrefixes ¶
TrimPrefixes trims the first path prefix matching value, used to prune known things from arbitrary path strings which may or may not be prefixed with any of the prefixes given
func TrimQuotes ¶
TrimQuotes returns the string with the first and last characters trimmed from the string if the string IsQuoted and returns the unmodified input string otherwise
func TrimTmplVar ¶ added in v1.1.0
TrimTmplVar returns the name with leading `$` and `.` characters removed
func UniqueFromSpaceSep ¶
UniqueFromSpaceSep splits the given value on spaces and only appends it to the original slice if not already present, returning the updated results
Types ¶
type ByteBuffer ¶
ByteBuffer is a wrapper around bytes.Buffer which implements the io.Closer interface so that it can be used in io.WriteCloser contexts
func NewByteBuffer ¶
func NewByteBuffer() (c *ByteBuffer)
NewByteBuffer returns a new ByteBuffer instance
func (*ByteBuffer) Close ¶
func (c *ByteBuffer) Close() error
Close fulfils the io.Closer interface and always returns nil because there isn't anything to actually close
type SortByLength ¶
type SortByLength []string
SortByLength implements the sort.Interface, sorting the slice from longest to shortest and sorting equal length strings using natural.Less
func (SortByLength) Len ¶
func (a SortByLength) Len() int
func (SortByLength) Less ¶
func (a SortByLength) Less(i, j int) bool
func (SortByLength) Swap ¶
func (a SortByLength) Swap(i, j int)