Attempt to improve the multicharacter detection code.

This commit is contained in:
Storm Dragon committed 2026-10-29 14:01:30 -04:00
1 parent 6fc3416a1b
commit 3cf41e662c
12 files changed
+1135 -843

No files matched your search

+17 -3
View File
@@ -47,10 +47,24 @@ func (p *Processor) process_token(token, level string, options TextOptions) stri
}
}
if options.RepeatedSymbols && options.RepeatedSymbolsMin >= 2 && token != "" {
char, _ := utf8.DecodeRuneInString(token)
repeated := token
prefix, suffix := "", ""
// Progress bars commonly enclose a repeated run in brackets. Keep
// those delimiters under ordinary punctuation handling, and require
// the entire interior to repeat so paths and mixed tokens stay literal.
if len(token) >= 2 {
for _, pair := range []string{"[]", "()", "{}", "<>"} {
if token[0] == pair[0] && token[len(token)-1] == pair[1] {
prefix, suffix = token[:1], token[len(token)-1:]
repeated = token[1 : len(token)-1]
break
}
}
}
char, _ := utf8.DecodeRuneInString(repeated)
if p.levels[level][char] && (unicode.IsPunct(char) || unicode.IsSymbol(char)) {
count := 0
for _, next := range token {
for _, next := range repeated {
if next != char {
return p.Text(token, level)
}
@@ -66,7 +80,7 @@ func (p *Processor) process_token(token, level string, options TextOptions) stri
name = i18n.T(name)
}
}
return i18n.Format("{0} {1}", strconv.Itoa(count), name)
return p.Text(prefix, level) + i18n.Format("{0} {1}", strconv.Itoa(count), name) + p.Text(suffix, level)
}
}
}