2026-03-07 05:30:18 +07:00

50 lines
906 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 re.ReplaceAllString(text, "")
}