This commit is contained in:
2026-03-02 02:25:22 +07:00
parent caaed14ebc
commit 5ab7ae0fcd
6 changed files with 94 additions and 51 deletions
+6
View File
@@ -0,0 +1,6 @@
package cleaner
type ICleaner interface {
// ([Ы-1]) -> ы1, Ы-1 -> ы1
ClearCode(code string) string
}
+41
View File
@@ -0,0 +1,41 @@
package cleaner
import "strings"
var (
replaceMap = map[string]string{
"a": "а",
"e": "е",
"o": "о",
"c": "с",
"p": "р",
"x": "х",
"y": "у",
"k": "к",
"m": "м",
"t": "т",
"h": "н",
"b": "в",
"u": "и",
}
)
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
}
+5
View File
@@ -0,0 +1,5 @@
package formatter
type IFormatter interface {
FormatText(text string) string
}
+39
View File
@@ -0,0 +1,39 @@
package formatter
import (
"bufio"
"strings"
)
type service struct{}
func NewFormatter() IFormatter {
return &service{}
}
func (s *service) FormatText(text string) string {
scanner := bufio.NewScanner(strings.NewReader(text))
scanner.Split(bufio.ScanLines)
lines := []string{}
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
var res strings.Builder
for i, line := range lines {
l := strings.TrimSpace(line)
if i == 0 && strings.HasPrefix(l, "—") {
res.WriteString(" ")
}
if i > 0 {
res.WriteString("\n")
if len(l) > 0 {
res.WriteString(" ")
}
}
res.WriteString(l)
}
return res.String()
}