Documentation
¶
Overview ¶
Package expr is part of the go-fastreport library, a pure Go port of FastReport .NET.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuiltinFunctions ¶
BuiltinFunctions returns a map of built-in function implementations for use in expr-lang/expr evaluation environments.
Available functions:
IIF(condition, trueVal, falseVal) – conditional expression Format(value, fmt) – string formatting DateDiff(date1, date2, unit) – date difference (unit: "days","hours","minutes","seconds") Str(value) – convert to string Int(value) – convert to int Float(value) – convert to float64 Len(s) – string length Upper(s) – uppercase Lower(s) – lowercase
Aggregate functions (Sum, Count, Avg, Min, Max) are registered externally by the engine because they require access to data source rows.
func ContainsExpression ¶
ContainsExpression returns true if text contains at least one [expression] with non-empty content between the brackets.
func ExtractExpressions ¶
ExtractExpressions returns only the expression strings from text.
func UnescapeBrackets ¶
UnescapeBrackets converts FastReport escape sequences in literal text. "[[" → "[" and "]]" → "]" per the .NET FastReport convention.
Types ¶
type EvalResult ¶
EvalResult holds the result of expression evaluation.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator compiles and evaluates FastReport expressions.
func NewEvaluator ¶
NewEvaluator creates a new Evaluator with the given environment.
func (*Evaluator) Eval ¶
Eval evaluates an expression string and returns the result. For simple variable references (identifiers without operators), it first looks up env directly for performance. For complex expressions it uses expr-lang/expr with a merged environment that includes built-in functions.
func (*Evaluator) EvalText ¶
EvalText evaluates all [expressions] in text, replacing them with their string representations and returning the full evaluated string.
type Token ¶
type Token struct {
// IsExpr is true when this token contains an expression (bracketed).
IsExpr bool
// Value is the literal text or expression string (without brackets).
Value string
}
Token represents a piece of parsed text.
func Parse ¶
Parse splits text into literal and expression tokens. Default brackets are "[" and "]". Example: "Hello [Name]!" → [{false,"Hello "}, {true,"Name"}, {false,"!"}]
func ParseWithBrackets ¶
ParseWithBrackets is like Parse but uses custom bracket characters. It handles nested brackets by tracking bracket depth. Escaped sequences "[[" and "]]" (double-open / double-close) are treated as literal single bracket characters in the output.