Skip to main content

The valueFormat definition

note

Work in progress.

Purpose

Control how an option's value is displayed in the configuration header file.

Syntax

{
"cdlOptions": {
"<name>": {
...
"valueFormat": "<expression>",
...
}
}
}

The value of the valueFormat property is a string containing a JavaScript expression.

Default value

The defaults depend on valueType:

  • none - undefined
  • bool - value ? "true" : "false"
  • int - parseInt(value).toString()
  • float - parseFloat(value).toString()
  • string - value.toString()

Description

For active and enabled objects, if the generatedDefinition property is defined, a line with the following structure will be generated in the file pointed by the generatedFile 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 changed 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.

info

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

eCos reference