diff options
author | Zhang Zhipeng <414326615@qq.com> | 2020-12-14 09:56:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 09:56:42 +0800 |
commit | ad79505173302fdd7619288b793497052e25a148 (patch) | |
tree | a3c994b63a6c0e32231f3ea10d4c87810d42796f /calc.go | |
parent | 61057c58d34c78232ad0a5c1702ea9fa25a7641a (diff) |
new formula func CLEAN and TRIM, change import path to v2 (#747)
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -3365,3 +3365,32 @@ func makeDate(y int, m time.Month, d int) int64 { func daysBetween(startDate, endDate int64) float64 { return float64(int(0.5 + float64((endDate-startDate)/86400))) } + +// Text Functions + +// CLEAN removes all non-printable characters from a supplied text string. +func (fn *formulaFuncs) CLEAN(argsList *list.List) (result string, err error) { + if argsList.Len() != 1 { + err = errors.New("CLEAN requires 1 argument") + return + } + b := bytes.Buffer{} + for _, c := range argsList.Front().Value.(formulaArg).String { + if c > 31 { + b.WriteRune(c) + } + } + result = b.String() + return +} + +// TRIM removes extra spaces (i.e. all spaces except for single spaces between +// words or characters) from a supplied text string. +func (fn *formulaFuncs) TRIM(argsList *list.List) (result string, err error) { + if argsList.Len() != 1 { + err = errors.New("TRIM requires 1 argument") + return + } + result = strings.TrimSpace(argsList.Front().Value.(formulaArg).String) + return +} |