stringcomparison

package
v0.0.0-...-aa62316 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompareStringsCharsResult

type CompareStringsCharsResult struct {
	SameChars       []rune
	SameCharsNoCase []rune
}

type CompareStringsResult

type CompareStringsResult struct {
	SameCharCount       int
	MatchPercent        float64
	SameCharCountNoCase int
	MatchPercentNoCase  float64
}

func CompareStrings

func CompareStrings(str1, str2 string) CompareStringsResult

CompareStrings takes two strings as input and returns a ComparisonResult struct containing various metrics that quantify their similarity.

Metrics included are:

- SameCharCount: The number of characters that are exactly the same at the corresponding positions in both strings.

- MatchPercent: 0 to 1. The percentage of characters that are exactly the same, calculated based on the shorter string's length.

- SameCharCountNoCase: The number of characters that are the same when case is ignored, at the corresponding positions in both strings.

- MatchPercentNoCase: 0 to 1. The percentage of characters that are the same when case is ignored, calculated based on the shorter string's length.

The function uses rune slices for Unicode support. It uses bitwise OR for fast ASCII character comparison, and falls back to unicode.SimpleFold for full Unicode case-insensitive comparison.

Jump to

Keyboard shortcuts

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