chore: add more tests (#2866)

* chore: add more tests

* chore: add more tests

* chore: fix test failure
This commit is contained in:
Kevin Wan
2023-02-11 14:21:39 +08:00
committed by kevin
parent 89f841c126
commit 04f181f0b4
6 changed files with 48 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package stringx
import "strings"
import (
"strings"
)
type (
// Replacer interface wraps the Replace method.
@@ -31,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 nextStart int
target := []rune(text)
cur := r.node
nextStart := 0
for len(target) != 0 {
used, jump, matched := cur.longestMatch(target, nextStart)
if matched {
@@ -53,5 +56,6 @@ func (r *replacer) Replace(text string) string {
}
}
}
return buf.String()
}