More work on repeated string summarization.
This commit is contained in:
1 parent
3cf41e662c
commit
47f18fdd28
7 files changed
+122
-34
No files matched your search
@@ -50,8 +50,8 @@ func (p *Processor) process_token(token, level string, options TextOptions) stri
|
||||
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.
|
||||
// those delimiters under ordinary punctuation handling. Inside them,
|
||||
// summarize each run, including partially filled bars such as [####----].
|
||||
if len(token) >= 2 {
|
||||
for _, pair := range []string{"[]", "()", "{}", "<>"} {
|
||||
if token[0] == pair[0] && token[len(token)-1] == pair[1] {
|
||||
@@ -61,16 +61,25 @@ func (p *Processor) process_token(token, level string, options TextOptions) stri
|
||||
}
|
||||
}
|
||||
}
|
||||
char, _ := utf8.DecodeRuneInString(repeated)
|
||||
if p.levels[level][char] && (unicode.IsPunct(char) || unicode.IsSymbol(char)) {
|
||||
count := 0
|
||||
for _, next := range repeated {
|
||||
if next != char {
|
||||
return p.Text(token, level)
|
||||
}
|
||||
count++
|
||||
chars := []rune(repeated)
|
||||
for _, char := range chars {
|
||||
if !(unicode.IsPunct(char) || unicode.IsSymbol(char)) || prefix == "" && char != chars[0] {
|
||||
return p.Text(token, level)
|
||||
}
|
||||
if count >= options.RepeatedSymbolsMin {
|
||||
}
|
||||
var result strings.Builder
|
||||
summarized := false
|
||||
for start := 0; start < len(chars); {
|
||||
char := chars[start]
|
||||
end := start + 1
|
||||
for end < len(chars) && chars[end] == char {
|
||||
end++
|
||||
}
|
||||
count := end - start
|
||||
if start > 0 {
|
||||
result.WriteByte(' ')
|
||||
}
|
||||
if p.levels[level][char] && count >= options.RepeatedSymbolsMin {
|
||||
name := p.Character(char)
|
||||
// G13's requested English summary is "5 number". Keep ordinary
|
||||
// hash feedback, custom names and localized profile names intact.
|
||||
@@ -80,8 +89,15 @@ func (p *Processor) process_token(token, level string, options TextOptions) stri
|
||||
name = i18n.T(name)
|
||||
}
|
||||
}
|
||||
return p.Text(prefix, level) + i18n.Format("{0} {1}", strconv.Itoa(count), name) + p.Text(suffix, level)
|
||||
result.WriteString(i18n.Format("{0} {1}", strconv.Itoa(count), name))
|
||||
summarized = true
|
||||
} else {
|
||||
result.WriteString(p.Text(string(chars[start:end]), level))
|
||||
}
|
||||
start = end
|
||||
}
|
||||
if summarized {
|
||||
return p.Text(prefix, level) + result.String() + p.Text(suffix, level)
|
||||
}
|
||||
}
|
||||
return p.Text(token, level)
|
||||
|
||||
Reference in new issue
Block a user