-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnormalize.go
More file actions
31 lines (28 loc) · 876 Bytes
/
normalize.go
File metadata and controls
31 lines (28 loc) · 876 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
package normalize
var defaultNormalizers = []Option{
WithRemoveSpecialChars(),
WithFixRareCyrillicChars(),
WithCyrillicToLatinLookAlike(),
WithUmlautToLatinLookAlike(),
WithLowerCase(),
}
// Normalize returns normalized string.
// If not normalizers specified default set of normalizers is used.
func Normalize(str string, normalizers ...Option) string {
if len(normalizers) == 0 {
normalizers = defaultNormalizers
}
result := str
for _, normalizer := range normalizers {
result = normalizer(result)
}
return result
}
// Many normalizes slice of strings returning new slice with normalized elements.
func Many(strings []string, normalizers ...Option) []string {
normalizedStrings := make([]string, 0, len(strings))
for _, str := range strings {
normalizedStrings = append(normalizedStrings, Normalize(str, normalizers...))
}
return normalizedStrings
}