add modules

This commit is contained in:
2026-07-13 23:52:04 +07:00
parent db746f2123
commit 2b11c49b3c
6 changed files with 224 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
package cleaner
import (
"regexp"
"strings"
)
var (
replaceMap = map[string]string{
"a": "а",
"e": "е",
"o": "о",
"c": "с",
"p": "р",
"x": "х",
"y": "у",
"k": "к",
"m": "м",
"t": "т",
"h": "н",
"b": "в",
"u": "и",
}
re = regexp.MustCompile(`\(\[[a-zA-Zа-яА-Я\d-]+\]\)`)
)
type service struct{}
func NewCleaner() ICleaner {
return &service{}
}
func (s *service) ClearCode(code string) string {
code = strings.TrimPrefix(code, "(")
code = strings.TrimPrefix(code, "[")
code = strings.TrimSuffix(code, ")")
code = strings.TrimSuffix(code, "]")
code = strings.ToLower(code)
code = strings.TrimSpace(code)
code = strings.ReplaceAll(code, "-", "")
for latin, cyrillic := range replaceMap {
code = strings.ReplaceAll(code, latin, cyrillic)
}
return code
}
func (s *service) ClearText(text string) string {
return strings.TrimSpace(re.ReplaceAllString(text, ""))
}