valueFormat property
Work in progress.
Purpose
Control how an option's value is displayed in the configuration header file.
Syntax
{
"cdlOptions | cdlComponents": [
{
"name": "...",
...
"valueFormat": "<expression>",
...
}
]
}
The value of the valueFormat property is a string containing a JavaScript
expression.
Default value
The defaults depend on valueType:
none-undefinedbool-value ? "true" : "false"int-parseInt(value).toString()float-parseFloat(value).toString()string-value.toString()
Description
For active and enabled objects, if the customDefine property is
defined, a line with the following structure will be generated in the file
pointed to by the headerFile property:
#define <name> (<value>)
For nodes of type none, the default definition includes only the name:
#define <name>
For string objects, a second line is generated, with the value appended to the name:
#define <name>_<value>
The value is slightly adjusted to uppercase and all non-letter characters are
replaced with _. Empty strings are suffixed with _EMPTY.
The valueFormat property can be set to a JavaScript expression. If the type is
none and the expression returns undefined, no value is shown. For all other
types, returning undefined triggers an error.
The implementation creates an internal JavaScript function that has an input
parameter named value and returns a string.
For security reasons, the string is not accepted if it includes words like
import or request.
Example
To format a 32bit hex value, a possible solution is:
"valueFormat": "const hex=parseInt(value).toString(16); return '0x'+'00000000'.substr(0, 8 - hex.length) + hex.toUpperCase()"
See also
customDefinepropertyvalueTypeproperty
eCos reference
define-formatproperty