base_from_calculate.go 737 B

1234567891011121314151617181920212223242526272829
  1. package services
  2. import (
  3. "strings"
  4. )
  5. // CheckFormula 检测计算公式是否异常
  6. func CheckFormula(formula string) map[string]string {
  7. mathFormula := []string{"MAX", "MIN", "ABS", "ACOS", "ASIN", "CEIL", "MOD", "POW", "ROUND", "SIGN", "SIN", "TAN", "LOG10", "LOG2", "LOG", "LN"}
  8. str := strings.ToUpper(formula)
  9. for _, v := range mathFormula {
  10. str = strings.Replace(str, v, "", -1)
  11. }
  12. str = strings.Replace(str, "(", "", -1)
  13. str = strings.Replace(str, ")", "", -1)
  14. byteMap := make(map[string]string)
  15. for i := 0; i < len(str); i++ {
  16. byteInt := str[i]
  17. if byteInt >= 65 && byteInt <= 90 {
  18. byteStr := string(byteInt)
  19. if _, ok := byteMap[byteStr]; !ok {
  20. byteMap[byteStr] = byteStr
  21. }
  22. }
  23. }
  24. return byteMap
  25. }