applyCastsInString processes cast overrides like int(${}) in string expressions, applying the cast to the corresponding ref value and stripping the cast syntax from the expression.
(expression string, refs []Value)
| 91 | } |
| 92 | return StringVal(b.String()), nil |
| 93 | } |
| 94 | |
| 95 | // applyCastsInString processes cast overrides like int(${}) in string |
| 96 | // expressions, applying the cast to the corresponding ref value and |
| 97 | // stripping the cast syntax from the expression. |
| 98 | func applyCastsInString(expression string, refs []Value) (string, []Value) { |
| 99 | result := make([]Value, len(refs)) |
| 100 | copy(result, refs) |
| 101 | |
| 102 | for { |
| 103 | loc := castOverrideRE.FindStringSubmatchIndex(expression) |
| 104 | if loc == nil { |
| 105 | break |
| 106 | } |
| 107 | castName := expression[loc[2]:loc[3]] |
| 108 | plIdx := len(placeholderRE.FindAllStringIndex(expression[:loc[0]], -1)) |
| 109 | targetType := castNameToDataType(castName) |
| 110 | result[plIdx] = result[plIdx].Cast(targetType) |
| 111 | expression = expression[:loc[0]] + "${}" + expression[loc[1]:] |
| 112 | } |
no test coverage detected