validator

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultValidationOptions = ValidationOptions{
	MaxExpressionLength:   1000,
	MaxNestedParentheses:  20,
	MaxFunctionArguments:  10,
	AllowedFunctions:      []string{},
	DisallowedFunctions:   []string{},
	AllowVariables:        true,
	MaxVariableNameLength: 50,
	MaxNumberLength:       50,
}

DefaultValidationOptions 默认验证选项

Functions

func SimplifyConsecutiveOperators

func SimplifyConsecutiveOperators(expression string) string

SimplifyConsecutiveOperators 简化连续的加减运算符

func ValidateAndSanitizeExpression

func ValidateAndSanitizeExpression(expression string, options ValidationOptions) (string, error)

ValidateAndSanitizeExpression 验证并净化表达式

func ValidateExpression

func ValidateExpression(expression string, options ValidationOptions) error

ValidateExpression 验证表达式

Types

type ValidationError

type ValidationError struct {
	Message string
	Pos     int
}

ValidationError 验证错误

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationOptions

type ValidationOptions struct {
	MaxExpressionLength   int      // 最大表达式长度
	MaxNestedParentheses  int      // 最大嵌套括号数
	MaxFunctionArguments  int      // 最大函数参数数量
	AllowedFunctions      []string // 允许的函数
	DisallowedFunctions   []string // 禁止的函数
	AllowVariables        bool     // 是否允许变量
	MaxVariableNameLength int      // 最大变量名长度
	MaxNumberLength       int      // 最大数字长度
}

ValidationOptions 验证选项

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL