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
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
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
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
Split splits its argument on sep. It is a convenience function for strings.Split, except that it returns empty if s == "".
func Trunc ¶
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.