strutil

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package strutil contains string-related utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CorrectPunctuation added in v0.1.14

func CorrectPunctuation(title string) string

CorrectPunctuation attempts to rewrite title to use typographically-correct punctuation characters.

func Normalize

func Normalize(orig string) string

Normalize normalizes characters using NFKD form. Unicode characters are decomposed (runes are broken into their components) and replaced for compatibility equivalence (characters that represent the same characters but have different visual representations, e.g. '9' and '⁹', are equal). Characters are also de-accented.

func Truncate added in v0.1.13

func Truncate(orig string, max int, elide bool) string

Truncate truncates orig to at most max UTF-8 characters. If elide is true, the final character of a truncated string is changed to "…".

Types

type Edits

type Edits struct{ Ins, Dels, Subs int }

Edits holds information about edits needed to transform one string into another.

func Levenshtein

func Levenshtein(as, bs string) Edits

Levenshtein computes the Levenshtein distance between a and b using the Wagner–Fischer algorithm. It's based on pseudocode from https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm.

func (Edits) Dist

func (e Edits) Dist() int

Dist returns the Levenshtein distance (i.e. total number of edits).

Jump to

Keyboard shortcuts

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