mirror of
https://github.com/nasa/fpp.git
synced 2025-12-18 02:51:07 -06:00
71 lines
2.7 KiB
Plaintext
71 lines
2.7 KiB
Plaintext
== Format Strings
|
|
|
|
A *format string* is a string that specifies the display format
|
|
of a
|
|
<<Definitions_Struct-Definitions,struct member>>,
|
|
<<Definitions_Array-Definitions,array element>>,
|
|
<<Specifiers_Event-Specifiers,event report>>, or
|
|
<<Specifiers_Telemetry-Channel-Specifiers,telemetry channel>>.
|
|
|
|
An FPP format string is similar to a
|
|
https://docs.python.org/3.0/library/string.html#formatstrings[Python format
|
|
string].
|
|
As in python, a format string consists of text containing one or more
|
|
*replacement fields* surrounded by curly braces `{` `}`.
|
|
In the output, each replacement field is replaced by the value of an
|
|
*argument*.
|
|
Characters outside of replacement fields are copied to the output unchanged,
|
|
except that the escape sequences `{{` and `}}` are converted to single
|
|
braces.
|
|
|
|
The number of arguments must match the number of replacement fields.
|
|
Each replacement field must also match the type of its argument, as
|
|
discussed below.
|
|
|
|
The following replacement fields are allowed:
|
|
|
|
. You can use the *default replacement field* `{}` to convert any argument.
|
|
It causes the argument to be displayed in a standard way
|
|
for F Prime according to its type.
|
|
|
|
. If the type of an argument _a_ is an
|
|
<<Types_Internal-Types_Integer-Types,integer type>>,
|
|
then you can use an *integer replacement field* to convert _a_.
|
|
An integer replacement field is one of the following:
|
|
|
|
.. `{c}`: Display _a_ as a character value.
|
|
|
|
.. `{d}`: Display _a_ as a decimal integer value
|
|
|
|
.. `{x}`: Display _a_ as a hexadecimal integer value.
|
|
|
|
.. `{o}`: Display _a_ as an octal integer value.
|
|
|
|
. If the type of an argument _a_ is a
|
|
<<Types_Floating-Point-Types,floating-point type>>,
|
|
then you can use a *rational replacement field* to convert _a_.
|
|
A rational replacement field is one of the following:
|
|
|
|
.. `{e}`: Display _a_ as a rational number using exponent notation, e.g., `1.234e2`
|
|
|
|
.. `{f}`: Display _a_ as a rational number using fixed-point notation, e.g., `123.4`.
|
|
|
|
.. `{g}`: Display _a_ as a rational number using general format. This format
|
|
uses fixed-point notation for
|
|
numbers up to some size _s_ and uses exponent notation for numbers larger than
|
|
_s_.
|
|
The value of _s_ is implementation-dependent.
|
|
|
|
.. One of the replacement fields denoted above, but with a period and a literal
|
|
decimal integer after the opening brace.
|
|
The integer value _n_ specifies the *precision*, i.e., the number of digits after
|
|
the decimal point for fixed-point notation, or before the `e` for exponent
|
|
notation.
|
|
For example, the replacement field `{.3f}`, specifies fixed-point notation
|
|
with a precision of 3.
|
|
_n_ must be in the range [0,100].
|
|
|
|
No other replacement fields are allowed.
|
|
No other use of `{` or `}` is allowed, except in the escape sequences
|
|
`{{` and `}}`.
|