fix voor zinnen aan elkaar
This commit is contained in:
@@ -13,10 +13,19 @@ import (
|
||||
var (
|
||||
p = e.PanicErr
|
||||
reEOL = regexp.MustCompile(`[.!?]['"”’]?$`)
|
||||
reNEOL = regexp.MustCompile(`[.!?]['"”’]?\p{Lu}\p{Ll}`)
|
||||
reNEOL = regexp.MustCompile(`[.!?]['"”’]?\p{Lu}\p{Ll}+\.?`)
|
||||
reLET = regexp.MustCompile(`\p{Lu}`)
|
||||
reBody = regexp.MustCompile(`<[bB][rR][ /]*>`)
|
||||
)
|
||||
|
||||
func HtmlFix(body []byte) []byte {
|
||||
return reBody.ReplaceAllLiteral(body, []byte(" "))
|
||||
}
|
||||
|
||||
func HtmlFixString(body string) string {
|
||||
return reBody.ReplaceAllLiteralString(body, " ")
|
||||
}
|
||||
|
||||
func AddEnd(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
@@ -28,12 +37,20 @@ func AddEnd(s string) string {
|
||||
return s + ".\n"
|
||||
}
|
||||
|
||||
func FixSpace(s string) string {
|
||||
func FixSpace(s string, opt ...bool) string {
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
s = reNEOL.ReplaceAllStringFunc(s, func(s1 string) string {
|
||||
i := reLET.FindStringIndex(s1)[0]
|
||||
return s1[:i] + " " + s1[i:]
|
||||
})
|
||||
|
||||
if len(opt) > 0 && opt[0] {
|
||||
s = reNEOL.ReplaceAllStringFunc(s, func(s1 string) string {
|
||||
if strings.HasSuffix(s1, ".") {
|
||||
// zoals: v.Chr.
|
||||
return s1
|
||||
}
|
||||
i := reLET.FindStringIndex(s1)[0]
|
||||
return s1[:i] + " " + s1[i:]
|
||||
})
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user