stringutil

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GlobStar is the "match anything" constant.
	GlobStar = "*"
)

Variables

View Source
var (
	// LowerLetters is a runset of lowercase letters.
	LowerLetters Runeset = []rune(`abcdefghijklmnopqrstuvwxyz`)

	// UpperLetters is a runset of uppercase letters.
	UpperLetters Runeset = []rune(`ABCDEFGHIJKLMNOPQRSTUVWXYZ`)

	// Letters is a runset of both lower and uppercase letters.
	Letters = append(LowerLetters, UpperLetters...)

	// Numbers is a runset of numeric characters.
	Numbers Runeset = []rune(`0123456789`)

	// LettersAndNumbers is a runset of letters and numeric characters.
	LettersAndNumbers = append(Letters, Numbers...)

	// Symbols is a runset of symbol characters.
	Symbols Runeset = []rune(`!@#$%^&*()_+-=[]{}\|:;`)

	// LettersNumbersAndSymbols is a runset of letters, numbers and symbols.
	LettersNumbersAndSymbols = append(LettersAndNumbers, Symbols...)
)

Functions

func CompressSpace

func CompressSpace(text string) (output string)

CompressSpace compresses whitespace characters into single spaces. It trims leading and trailing whitespace as well.

func Fields

func Fields(text string) (output []string)

Fields splits a corpus on space but treats quoted strings, specifically any text within `"` as individual fields.

func Glob

func Glob(subj, pattern string) bool

Glob returns if a subject matches a given pattern.

func GlobAny

func GlobAny(subj string, patterns ...string) bool

GlobAny tests if a file matches a (potentially) csv of glob filters.

func Slugify

func Slugify(v string) string

Slugify replaces non-letter or digit runes with '-'. It will not add repeated '-'.

func SplitLines

func SplitLines(contents string) []string

SplitLines splits the contents by the ascii control character `\n` with the default options applied.

To set options yourself, use `SplitLinesOptions{}.SplitLines(contents)`.

func SplitQuoted

func SplitQuoted(text, sep string) (output []string)

SplitQuoted splits a corpus on a given string but treats quoted strings, specifically any text within `"` as whole values.

func Table

func Table(wr io.Writer, columns []string, rows [][]string) error

Table writes a table to a given writer.

func TableForSlice

func TableForSlice[A any](wr io.Writer, collection []A) error

TableForSlice prints a table for a given slice. It will infer column names from the struct fields. If it is a mixed array (i.e. []interface{}) it will probably panic.

func TrimQuotes

func TrimQuotes(v string) string

TrimQuotes trims the leading and trailing characters that match the `fieldIsQuote` function.

Types

type Runeset

type Runeset []rune

Runeset is a set of runes

func (Runeset) Len

func (rs Runeset) Len() int

Len implements part of sorter.

func (Runeset) Less

func (rs Runeset) Less(i, j int) bool

Less implements part of sorter.

func (Runeset) Random

func (rs Runeset) Random(length int) string

Random returns a random selection of runes from the set.

func (Runeset) RandomProvider

func (rs Runeset) RandomProvider(provider *rand.Rand, length int) string

RandomProvider returns a random selection of runes from the set.

func (Runeset) Swap

func (rs Runeset) Swap(i, j int)

Swap implements part of sorter.

type SplitLinesOptions

type SplitLinesOptions struct {
	SkipTrailingNewline bool
	SkipEmptyLines      bool
}

SplitLinesOptions are options for the SplitLines function.

var DefaultSplitLinesOptions SplitLinesOptions

DefaultSplitLinesOptions are the default split lines options.

func (SplitLinesOptions) SplitLines

func (opts SplitLinesOptions) SplitLines(contents string) []string

SplitLines splits a corpus into individual lines by the ascii control character `\n`. You can control some behaviors of the splitting process with variadic options.

Jump to

Keyboard shortcuts

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