lstr

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPreprocess = func(str string) (skip bool, cleaned string) {
	cleaned = strings.TrimSpace(str)
	skip = cleaned == ""
	return
}
View Source
var NumericReplacer = NewRemover(",", "$", "%")

Functions

func Glue

func Glue(strs ...string) string

Glue strings together with no joining string. Equivalent to strings.Join(strs, "")

func Len

func Len(s string) int

Len creates a strongly typed version of builtin len for strings.

func NewRemover

func NewRemover(rm ...string) *strings.Replacer

func ScannerFactory

func ScannerFactory(str string) liter.Factory[rune]

ScannerFactory creates a function to fulfill liter.Factory[rune] that is backed by a Scanner.

Types

type And

type And []Matcher

And takes many Matcher and returns true if all of them return true for a rune.

func (And) Matches

func (a And) Matches(r rune) bool

Matches returns true if all of the Matchers return true for a rune.

type Joiner

type Joiner struct {
	Elems []string
	Seperator
}

Joiner wraps strings.Join. This allows it to be invoked lazily.

func (*Joiner) String

func (j *Joiner) String() string

Stirng fulfills fmt.Stringer and calls strings.Join.

type Matcher

type Matcher interface {
	Matches(r rune) bool
}

Matcher returns true when a rune matches some criteria.

type MatcherFunc

type MatcherFunc func(r rune) bool

MatcherFunc wraps a func so it fulfills Matcher.

func (MatcherFunc) Matches

func (fn MatcherFunc) Matches(r rune) bool

Matches calls the underlying MatcherFunc.

type Not

type Not struct {
	Matcher
}

Not takes a Matcher and inverts the output.

func (Not) Matches

func (n Not) Matches(r rune) bool

Matches inverts the output of the underlying Matcher.

type Or

type Or []Matcher

Or takes many Matcher and returns true if any of them return true for a rune.

func (Or) Matches

func (o Or) Matches(r rune) bool

Matches returns true if any of the Matchers return true for r.

type Range

type Range [2]rune

Range fulfills Matcher returning true when when given a rune that is between the two values (inclusivly).

func (Range) Matches

func (rng Range) Matches(r rune) bool

Matches fulfills Matcher returning true when when given a rune that is between the two values (inclusivly).

type Rune

type Rune rune

Rune fulfills Matcher returning true for an exact match

func (Rune) Matches

func (rn Rune) Matches(r rune) bool

Matches fulfills Matcher returning true when Rune == r

type Scanner

type Scanner struct {
	// Str is the string as a byte slice
	Str []byte
	// I is the index of the current rune
	I int
	// Count is the number of runes read
	Count int
	// Rune at the current position
	Rune rune
	// Size of the current rune
	Size int
}

Scanner is used it iterate over the runes in a string. Scanner fulfills Iter[rune].

func NewScanner

func NewScanner(str string) *Scanner

NewScanner creates a Scanner for the string.

func (*Scanner) Cur

func (s *Scanner) Cur() (r rune, done bool)

Cur returns the current rune and a bool indicating if the scanner is done.

func (*Scanner) Done

func (s *Scanner) Done() bool

Done returns true if I is at or past the end of the string.

func (*Scanner) Idx

func (s *Scanner) Idx() int

Idx returns the index of the current rune. The index will skip values if there are runes that take multiple bytes.

func (*Scanner) Iter

func (s *Scanner) Iter() liter.Wrapper[rune]

Iter returns a wrapped iterator.

func (*Scanner) Many

func (s *Scanner) Many(m Matcher) bool

Many checks if the current rune againts m and if it matches iterates until it reaches a rune that does not or reaches the end of the string. The returned bool indicates if it found at least one match.

func (*Scanner) Match

func (s *Scanner) Match(m Matcher) bool

Match checks if the current rune against m and returns the bool. If it is is a match, the Scanner moves to the next value.

func (*Scanner) Next

func (s *Scanner) Next() (r rune, done bool)

Next increments the Scanner.

func (*Scanner) Peek

func (s *Scanner) Peek(m Matcher) bool

Peek passes the current rune into m and returns the bool.

func (*Scanner) Reset

func (s *Scanner) Reset()

Reset the scanner back to the start of the string.

type Seperator

type Seperator string

Seperator is used for string operations with a seperator

func (Seperator) BufJoin

func (s Seperator) BufJoin(elems []string, buf []byte) string

BufJoin joins elems making sure there is a single Seperator between each elem and will use buf if it has adequit capacity.

func (Seperator) Index

func (s Seperator) Index(str string) int

Index is a wrapper around strings.Index

func (Seperator) Join

func (s Seperator) Join(elems ...string) string

Join elems making sure there is a single Seperator between each elem.

func (Seperator) JoinLen

func (s Seperator) JoinLen(elems []string) int

JoinLen returns the length of joining the elements with a single Seperator. This is used by Join to allocate the correct size slice for the output.

func (Seperator) Joiner

func (s Seperator) Joiner(elems ...string) *Joiner

Joiner creates an instance of Joiner with the given elements.

func (Seperator) Split

func (s Seperator) Split(str string) slice.Slice[string]

Split is a wrapper around strings.Split

type Strings

type Strings struct {
	Strings         []string
	Err             error
	Preprocess      func(string) (skip bool, cleaned string)
	NumericReplacer *strings.Replacer
	// contains filtered or unexported fields
}

Strings is helpful when processing a list of strings, often the result of splitting.

func NewStrings

func NewStrings(strs []string) *Strings

func (*Strings) Cur

func (s *Strings) Cur() (str string, done bool)

func (*Strings) Date

func (s *Strings) Date(layout string) (t time.Time)

func (*Strings) Done

func (s *Strings) Done() bool

func (*Strings) Float64

func (s *Strings) Float64() (f float64)

func (*Strings) Idx

func (s *Strings) Idx() int

func (*Strings) Int

func (s *Strings) Int() (i int)

func (*Strings) Len

func (s *Strings) Len() int

func (*Strings) Next

func (s *Strings) Next() (str string, done bool)

func (*Strings) Regex

func (s *Strings) Regex(re *regexp.Regexp, skipEmpty bool) []string

func (*Strings) Start

func (s *Strings) Start() (str string, done bool)

func (*Strings) Sub

func (s *Strings) Sub(split string) *Strings

type SubStrings

type SubStrings [][2]uint

SubStrings represents a slice of substrings by index.

func CamelCase

func CamelCase(str string) SubStrings

CamelCase logic is used to split a string into words.

func SubStringBySplit

func SubStringBySplit(splits []int) SubStrings

SubStringBySplit creates a SubStrings slice by splitting the string into sections so that the end of each range is equal to the start of the next.

func TransitionSplit

func TransitionSplit(m Matcher, str string) SubStrings

TransitionSplit takes a Matcher and each place where the result transitions from false to true there is a split.

func (SubStrings) Slice

func (s SubStrings) Slice(str string) []string

Slice applies the SubStrings to str and returns a slice of strings.

Jump to

Keyboard shortcuts

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