mstr

package
v0.14.7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: BSD-3-Clause Imports: 2 Imported by: 4

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.

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.

func Trunc

func Trunc(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