str

package standard library
go1.23.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package str provides string manipulation utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FoldDup

func FoldDup(list []string) (string, string)

FoldDup reports a pair of strings from the list that are equal according to strings.EqualFold. It returns "", "" if there are no such strings.

func HasFilePathPrefix added in go1.10

func HasFilePathPrefix(s, prefix string) bool

HasFilePathPrefix reports whether the filesystem path s begins with the elements in prefix.

HasFilePathPrefix is case-sensitive (except for volume names) even if the filesystem is not, does not apply Unicode normalization even if the filesystem does, and assumes that all path separators are canonicalized to filepath.Separator (as returned by filepath.Clean).

func HasPathPrefix added in go1.11

func HasPathPrefix(s, prefix string) bool

HasPathPrefix reports whether the slash-separated path s begins with the elements in prefix.

func QuoteGlob added in go1.19

func QuoteGlob(s string) string

QuoteGlob returns s with all Glob metacharacters quoted. We don't try to handle backslash here, as that can appear in a file path on Windows.

func StringList

func StringList(args ...any) []string

StringList flattens its arguments into a single []string. Each argument in args must have type string or []string.

func ToFold

func ToFold(s string) string

ToFold returns a string with the property that

strings.EqualFold(s, t) iff ToFold(s) == ToFold(t)

This lets us test a large set of strings for fold-equivalent duplicates without making a quadratic number of calls to EqualFold. Note that strings.ToUpper and strings.ToLower do not have the desired property in some corner cases.

func TrimFilePathPrefix added in go1.18

func TrimFilePathPrefix(s, prefix string) string

TrimFilePathPrefix returns s without the leading path elements in prefix, such that joining the string to prefix produces s.

If s does not start with prefix (HasFilePathPrefix with the same arguments returns false), TrimFilePathPrefix returns s. If s equals prefix, TrimFilePathPrefix returns "".

func Uniq added in go1.16

func Uniq(ss *[]string)

Uniq removes consecutive duplicate strings from ss.

func WithFilePathSeparator added in go1.21.0

func WithFilePathSeparator(s string) string

WithFilePathSeparator returns s with a trailing path separator, or the empty string if s is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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