zstrings

package
v0.0.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadPattern indicates a pattern was malformed.
	ErrBadPattern = errors.New("zstrings: syntax error in pattern")
)

Functions

func CountByteLeft

func CountByteLeft(s string, b byte) int

CountByteLeft counts the number of b from the lest side of s until non b found. For example, CountByteLeft("aabc",'a') returns 2.

func CountByteRight

func CountByteRight(s string, b byte) int

CountByteRight counts the number of b from the right side of s until non b found. For example, CountByteRight("abcc",'c') returns 2.

func CutLeftByte

func CutLeftByte(s string, c byte) (before, after string, found bool)

CutLeftByte slices the given string s at the first instance of c, returning the text before and after the separator of c. The found result reports whether c appears in s. The separator c is not contained both before and after. If the separator c does not appear in s, cut returns s, "", false. See also strings.Cut and strings.IndexByte.

func CutLeftRune

func CutLeftRune(s string, r rune) (before, after string, found bool)

CutLeftRune slices the given string s at the first instance of r, returning the text before and after the separator of r. The found result reports whether r appears in s. The separator r is not contained both before and after. If the separator r does not appear in s, cut returns s, "", false. If the given r is not valid UTF-8 rune, it also returns s, "", false. CutLeftRune uses Brute Force strategy for all s. See also strings.IndexRune.

func CutRightByte

func CutRightByte(s string, c byte) (before, after string, found bool)

CutRightByte slices the given string s at the last instance of c, returning the text before and after the separator of c. The found result reports whether c appears in s. The separator c is not contained both before and after. If the separator c does not appear in s, cut returns s, "", false. See also strings.Cut and strings.LastIndexByte.

func CutRightRune

func CutRightRune(s string, r rune) (before, after string, found bool)

CutRightRune slices the given string s at the last instance of r, returning the text before and after the separator of r. The found result reports whether r appears in s. The separator r is not contained both before and after. If the separator r does not appear in s, cut returns s, "", false. If the given r is not valid UTF-8 rune, it also returns s, "", false. CutLeftRune uses Brute Force strategy for all s. See also strings.IndexRune.

func Match

func Match(pattern, str string) (bool, error)

Match reports whether the str matches the pattern. Match is simpler and faster match function similar to path.Match or path/filepath.Match. The only error returned is ErrBadPattern when the given pattern has single "\\" at the end of its pattern.

The pattern syntax is:

pattern:
	{ term }
term:
	'*'         matches any sequence of characters
	'?'         matches any single character
	c           matches character c (c != '*', '?')
	'\\' c      matches character c

Types

This section is empty.

Jump to

Keyboard shortcuts

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