diff options
author | Eng Zer Jun <engzerjun@gmail.com> | 2022-06-12 00:19:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-12 00:19:12 +0800 |
commit | 6bcf5e4ede160af2ad04f5e69636211a5ced132d (patch) | |
tree | 836568f4c83f24d87acbd26f172f967c7a6a1118 /calc.go | |
parent | f5d3d59d8c65d9396893ae0156fef21592f6f425 (diff) |
refactor: replace strings.Replace with strings.ReplaceAll (#1250)
strings.ReplaceAll(s, old, new) is a wrapper function for
strings.Replace(s, old, new, -1). But strings.ReplaceAll is more
readable and removes the hardcoded -1.
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1360,7 +1360,7 @@ func (f *File) parseToken(sheet string, token efp.Token, opdStack, optStack *Sta // parseReference parse reference and extract values by given reference // characters and default sheet name. func (f *File) parseReference(sheet, reference string) (arg formulaArg, err error) { - reference = strings.Replace(reference, "$", "", -1) + reference = strings.ReplaceAll(reference, "$", "") refs, cellRanges, cellRefs := list.New(), list.New(), list.New() for _, ref := range strings.Split(reference, ":") { tokens := strings.Split(ref, "!") @@ -2065,13 +2065,13 @@ func cmplx2str(num complex128, suffix string) string { c = strings.TrimSuffix(c, "+0i") c = strings.TrimSuffix(c, "-0i") c = strings.NewReplacer("+1i", "+i", "-1i", "-i").Replace(c) - c = strings.Replace(c, "i", suffix, -1) + c = strings.ReplaceAll(c, "i", suffix) return c } // str2cmplx convert complex number string characters. func str2cmplx(c string) string { - c = strings.Replace(c, "j", "i", -1) + c = strings.ReplaceAll(c, "j", "i") if c == "i" { c = "1i" } @@ -13489,7 +13489,7 @@ func (fn *formulaFuncs) SUBSTITUTE(argsList *list.List) formulaArg { text, oldText := argsList.Front().Value.(formulaArg), argsList.Front().Next().Value.(formulaArg) newText, instanceNum := argsList.Front().Next().Next().Value.(formulaArg), 0 if argsList.Len() == 3 { - return newStringFormulaArg(strings.Replace(text.Value(), oldText.Value(), newText.Value(), -1)) + return newStringFormulaArg(strings.ReplaceAll(text.Value(), oldText.Value(), newText.Value())) } instanceNumArg := argsList.Back().Value.(formulaArg).ToNumber() if instanceNumArg.Type != ArgNumber { @@ -14804,7 +14804,7 @@ func (fn *formulaFuncs) ENCODEURL(argsList *list.List) formulaArg { return newErrorFormulaArg(formulaErrorVALUE, "ENCODEURL requires 1 argument") } token := argsList.Front().Value.(formulaArg).Value() - return newStringFormulaArg(strings.Replace(url.QueryEscape(token), "+", "%20", -1)) + return newStringFormulaArg(strings.ReplaceAll(url.QueryEscape(token), "+", "%20")) } // Financial Functions |