strutil

package
v0.312.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 2,063

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSyntax = errors.New("invalid syntax")

ErrSyntax indicates that a value does not have the right syntax for the target type.

Functions

func GraphLinkForExpression

func GraphLinkForExpression(expr string) string

GraphLinkForExpression creates an escaped relative link to the graph view of the provided expression.

func SanitizeFullLabelName added in v0.43.0

func SanitizeFullLabelName(name string) string

SanitizeFullLabelName replaces any invalid character with an underscore, and if given an empty string, returns a string containing a single underscore.

func SanitizeLabelName

func SanitizeLabelName(name string) string

SanitizeLabelName replaces anything that doesn't match client_label.LabelNameRE with an underscore. Note: this does not handle all Prometheus label name restrictions (such as not starting with a digit 0-9), and hence should only be used if the label name is prefixed with a known valid string.

func TableLinkForExpression

func TableLinkForExpression(expr string) string

TableLinkForExpression creates an escaped relative link to the table view of the provided expression.

func Unquote

func Unquote(s string) (t string, err error)

Unquote interprets s as a single-quoted, double-quoted, or backquoted Prometheus query language string literal, returning the string value that s quotes.

Types

type JaroWinklerMatcher added in v0.312.0

type JaroWinklerMatcher struct {
	// contains filtered or unexported fields
}

JaroWinklerMatcher pre-computes the encoding of a fixed search term so that it can be scored against many candidate strings without repeating the ASCII check or rune conversion on the term for every call. The first Score call with a Unicode candidate lazily caches the term's rune slice. It is not safe for concurrent use.

func NewJaroWinklerMatcher added in v0.312.0

func NewJaroWinklerMatcher(term string) *JaroWinklerMatcher

NewJaroWinklerMatcher returns a matcher for the given term.

func (*JaroWinklerMatcher) Score added in v0.312.0

func (m *JaroWinklerMatcher) Score(s string) float64

Score returns the Jaro-Winkler similarity between the matcher's term and s, in [0.0, 1.0] where 1.0 means identical strings.

type SubsequenceMatcher added in v0.312.0

type SubsequenceMatcher struct {
	// contains filtered or unexported fields
}

SubsequenceMatcher pre-computes the encoding of a fixed search pattern so that it can be scored against many candidate strings without repeating the ASCII check or rune conversion on the pattern for every call. The first Score call with a Unicode candidate lazily caches the pattern's rune slice. It is not safe for concurrent use.

func NewSubsequenceMatcher added in v0.312.0

func NewSubsequenceMatcher(pattern string) *SubsequenceMatcher

NewSubsequenceMatcher returns a matcher for the given pattern.

func (*SubsequenceMatcher) Score added in v0.312.0

func (m *SubsequenceMatcher) Score(text string) float64

Score computes a fuzzy match score between the matcher's pattern and text using a greedy character matching algorithm. Characters in pattern must appear in text in order (subsequence matching). The score is normalized to [0.0, 1.0] where:

  • 1.0 means exact match only.
  • 0.0 means no match (pattern is not a subsequence of text).
  • Intermediate values reward consecutive matches and penalize gaps.

This is a simple scorer for autocomplete ranking. It does not try every possible match, so it may miss the best score when the pattern can match the text in more than one way.

The raw scoring formula is: Σ(interval_size²) − Σ(gap_size / text_length) − trailing_gap / (2 * text_length). The result is normalized by pattern_length² (the maximum possible raw score).

Jump to

Keyboard shortcuts

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