mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 16:29:18 +00:00
026055a0b7
Bumps [github.com/urfave/cli/v2](https://github.com/urfave/cli) from 2.3.0 to 2.27.1. - [Release notes](https://github.com/urfave/cli/releases) - [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md) - [Commits](https://github.com/urfave/cli/compare/v2.3.0...v2.27.1) --- updated-dependencies: - dependency-name: github.com/urfave/cli/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
42 lines
839 B
Go
42 lines
839 B
Go
package smetrics
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// The Soundex encoding. It is a phonetic algorithm that considers how the words sound in English. Soundex maps a string to a 4-byte code consisting of the first letter of the original string and three numbers. Strings that sound similar should map to the same code.
|
|
func Soundex(s string) string {
|
|
m := map[byte]string{
|
|
'B': "1", 'P': "1", 'F': "1", 'V': "1",
|
|
'C': "2", 'S': "2", 'K': "2", 'G': "2", 'J': "2", 'Q': "2", 'X': "2", 'Z': "2",
|
|
'D': "3", 'T': "3",
|
|
'L': "4",
|
|
'M': "5", 'N': "5",
|
|
'R': "6",
|
|
}
|
|
|
|
s = strings.ToUpper(s)
|
|
|
|
r := string(s[0])
|
|
p := s[0]
|
|
for i := 1; i < len(s) && len(r) < 4; i++ {
|
|
c := s[i]
|
|
|
|
if (c < 'A' || c > 'Z') || (c == p) {
|
|
continue
|
|
}
|
|
|
|
p = c
|
|
|
|
if n, ok := m[c]; ok {
|
|
r += n
|
|
}
|
|
}
|
|
|
|
for i := len(r); i < 4; i++ {
|
|
r += "0"
|
|
}
|
|
|
|
return r
|
|
}
|