mstr

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: BSD-3-Clause Imports: 2 Imported by: 6

Documentation

Overview

Package mstr defines utility functions for strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareNatural added in v0.14.7

func CompareNatural(a, b string) int

CompareNatural compares its arguments lexicographically, but treats runs of decimal digits as the spellings of natural numbers and compares their values instead of the individual digits.

For example, "a2b" is after "a12b" under ordinary lexicographic comparison, but before under CompareNatural, because 2 < 12. However, if one argument has digits and the other has non-digits at that position (see for example "a" vs. "12") the comparison falls back to lexicographic.

CompareNatural returns -1 if a < b, 0 if a == b, and +1 if a > b. It does not allocate memory.

func Lines added in v0.13.3

func Lines(s string) []string

Lines splits its argument on newlines. It is a convenience function for strings.Split, except that it returns empty if s == "" and treats a trailing newline as the end of the file rather than an empty line.

func Match added in v0.25.1

func Match(s, pattern string) bool

Match reports whether s matches the specified pattern. An occurrence of "*" in the pattern matches zero or more arbitrary bytes in s; otherwise the corresponding positions of s and the pattern must be equal.

Match takes time proportional to the lengths of its arguments, and does not allocate memory.

func Split added in v0.22.0

func Split(s, sep string) []string

Split splits its argument on sep. It is a convenience function for strings.Split, except that it returns empty if s == "".

func Trunc

func Trunc[String ~string | ~[]byte](s String, n int) String

Trunc returns a prefix of s having length no greater than n bytes. If s exceeds this length, it is truncated at a point ≤ n so that the result does not end in a partial UTF-8 encoding. Trunc does not verify that s is valid UTF-8, but if it is the result will remain valid after truncation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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