-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnormalize.go
More file actions
44 lines (35 loc) · 1011 Bytes
/
normalize.go
File metadata and controls
44 lines (35 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-FileCopyrightText: 2023 Adriano Prado <dev@dude333.com>
//
// SPDX-License-Identifier: MIT
package rapina
import (
"strings"
"unicode"
"github.com/dude333/rslp-go"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func removeAccent(str string) string {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
result, _, _ := transform.String(t, str)
return result
}
func NormalizeString(s string) string {
// Converte para minúsculas e remove espaços em branco
s = strings.ToLower(s)
s = strings.ReplaceAll(s, " ", "")
// Remove caracteres especiais
var normalized []rune
for _, char := range s {
if unicode.IsLetter(char) || unicode.IsDigit(char) {
normalized = append(normalized, char)
}
}
return removeAccent(string(normalized))
}
func Similar(s1, s2 string) bool {
normalizedS1 := NormalizeString(rslp.Frase(s1))
normalizedS2 := NormalizeString(rslp.Frase(s2))
return normalizedS1 == normalizedS2
}