chore: refactor (#2875)

This commit is contained in:
Kevin Wan
2023-02-12 22:20:36 +08:00
committed by kevin
parent 95d7c73409
commit 016d965f56
3 changed files with 49 additions and 30 deletions

View File

@@ -33,9 +33,10 @@ func NewReplacer(mapping map[string]string) Replacer {
// Replace replaces text with given substitutes.
func (r *replacer) Replace(text string) string {
var buf strings.Builder
var paths []*node
target := []rune(text)
cur := r.node
var paths []*node
for len(target) != 0 {
uselessLen, matchLen, nextPaths := cur.longestMatch(target, paths)
if uselessLen > 0 {
@@ -54,5 +55,6 @@ func (r *replacer) Replace(text string) string {
paths = nil
}
}
return buf.String()
}