str

package
v0.0.0-...-c9bb408 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package strs has miscellaneous functions for slices of strings

Package str has miscellaneous string functions Uses ascii package for lower/upper case

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterFirst

func AfterFirst(s, sub string) string

AfterFirst returns s up to the first occurrence of sub or all of s if sub is not found.

func AfterLast

func AfterLast(s, sub string) string

AfterLast returns s after the last occurrence of sub or all of s if sub is not found.

func BeforeFirst

func BeforeFirst(s, sub string) string

BeforeFirst returns s up to the first occurrence of sub or all of s if sub is not found.

func BeforeLast

func BeforeLast(s, sub string) string

BeforeLast returns s before the last occurrence of sub or all of s if sub is not found.

func Capitalize

func Capitalize(s string) string

Capitalize returns the string with the first letter converted from a-z to A-Z

func Capitalized

func Capitalized(s string) bool

Capitalized returns true is the string starts with A-Z, otherwise false

func CmpLower

func CmpLower(s1, s2 string) int

CmpLower compares the ascii.ToLower of each character returning -1, 0, or +1 similar to strings.Compare

func Cut

func Cut(s string, sep byte) (before, after string)

Cut slices s around the first instance of sep, returning the text before and after sep. If sep does not appear in s, cut returns s, "". Similar to the Go 1.18 strings.Cut (except it uses a string separator)

func Doesc

func Doesc(s string, i int) (byte, int)

Doesc returns the next byte, interpreting escape sequences

func EqualCI

func EqualCI(x, y string) bool

EqualCI checks if two strings are equal ignoring (ascii) case

func Find1of

func Find1of(s, chars string) int

func FindLast1of

func FindLast1of(s, chars string) int

func IndexFunc

func IndexFunc(s string, f func(byte) bool) int

IndexFunc returns the index of the first byte that the func returns true for else -1

func Join

func Join(fmt string, list []string) string

Join joins strings with the specified format. The format may include delimiters e.g. "(,)"

func Opt

func Opt(strs ...string) string

Opt returns "" if any of the strings are "" else it returns the concatenation of the strings. e.g. Opt("=", s) or Opt(s, ",") or Opt("<", s, ">")

func Random

func Random(min, max int) string

func RandomOf

func RandomOf(min, max int, chars string) string

func Split

func Split(s, sep string) []string

Split returns nil if s is "", otherwise it returns strings.Split

func Subi

func Subi(s string, i, j int) string

Subi returns the substring specified by a starting index and a limit index allowing indexes to exceed the string

func Subn

func Subn(s string, i, n int) string

Subn returns the substring specified by a starting index and a length allows index and length to exceed the string

func ToLower

func ToLower(s string) string

ToLower is an ascii version of strings.ToLower

func ToUpper

func ToUpper(s string) string

ToUpper is an ascii version os strings.ToUpper

func UnCapitalize

func UnCapitalize(s string) string

UnCapitalize returns the string with the first letter converted from A-Z to a-z

func UniqueRandom

func UniqueRandom(min, max int, seed ...int64) func() string

func UniqueRandomOf

func UniqueRandomOf(min, max int, chars string, seed ...int64) func() string

Types

type CommaBuilder

type CommaBuilder struct {
	// contains filtered or unexported fields
}

CommaBuilder builds a comma separated list. Zero value is ready to use.

func (*CommaBuilder) Add

func (cb *CommaBuilder) Add(s string)

Add adds a string to the list

func (*CommaBuilder) String

func (cb *CommaBuilder) String() string

String returns the comma separated list

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func (*Queue) Add

func (q *Queue) Add(s string)

Add adds a string to the end of the queue.

func (*Queue) Empty

func (q *Queue) Empty() bool

Empty returns true is the queue is empty, otherwise false.

func (*Queue) Take

func (q *Queue) Take() string

Take removes and returns the first string in the queue (FIFO). Will panic if queue is empty.

Jump to

Keyboard shortcuts

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