Renovate Bot
b792a8f374
Some checks are pending
Dev Version / Release (push) Waiting to run
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/urfave/cli/v2](https://github.com/urfave/cli) | require | minor | `v2.25.7` -> `v2.27.4` | > ❗ **Important** > > Release Notes retrieval for this PR were skipped because no github.com credentials were available. > If you are self-hosted, please see [this instruction](https://github.com/renovatebot/renovate/blob/master/docs/usage/examples/self-hosting.md#githubcom-token-for-release-notes). --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMS4yIiwidXBkYXRlZEluVmVyIjoiMzguMjEuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Reviewed-on: #5 Co-authored-by: Renovate Bot <renovate@keks.cloud> Co-committed-by: Renovate Bot <renovate@keks.cloud>
63 lines
1 KiB
Go
63 lines
1 KiB
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 {
|
|
b := strings.Builder{}
|
|
b.Grow(4)
|
|
|
|
p := s[0]
|
|
if p <= 'z' && p >= 'a' {
|
|
p -= 32 // convert to uppercase
|
|
}
|
|
b.WriteByte(p)
|
|
|
|
n := 0
|
|
for i := 1; i < len(s); i++ {
|
|
c := s[i]
|
|
|
|
if c <= 'z' && c >= 'a' {
|
|
c -= 32 // convert to uppercase
|
|
} else if c < 'A' || c > 'Z' {
|
|
continue
|
|
}
|
|
|
|
if c == p {
|
|
continue
|
|
}
|
|
|
|
p = c
|
|
|
|
switch c {
|
|
case 'B', 'P', 'F', 'V':
|
|
c = '1'
|
|
case 'C', 'S', 'K', 'G', 'J', 'Q', 'X', 'Z':
|
|
c = '2'
|
|
case 'D', 'T':
|
|
c = '3'
|
|
case 'L':
|
|
c = '4'
|
|
case 'M', 'N':
|
|
c = '5'
|
|
case 'R':
|
|
c = '6'
|
|
default:
|
|
continue
|
|
}
|
|
|
|
b.WriteByte(c)
|
|
n++
|
|
if n == 3 {
|
|
break
|
|
}
|
|
}
|
|
|
|
for i := n; i < 3; i++ {
|
|
b.WriteByte('0')
|
|
}
|
|
|
|
return b.String()
|
|
}
|