TDes8::Format()
,
TDes16::Format()
and some other functions take a format
string containing literal text embedded with directives for converting a
trailing list of arguments into text. Each formatting directive consumes a
number of arguments from the trailing list; almost always one. Directives have
the following syntax:
<format-directive>
::=<escaped-percent>
|
<simple-conversion>
|
<padded-conversion>
|
<aligned-conversion>
<escaped-percent>
::=%%
"Formatting directives begin with a "%
". To insert a
percentage sign, use the digraph "%%
".
<simple-conversion>
::=%
"
<conversion-specifier>
Unpadded, dynamic-width formatting. Data from the argument list is converted without padding, and only occupies the space required. The conversion specifier descibes how the data is to be formatted into a string.
<padded-conversion>
::=%
"
<zero-or-space-pad>
<field-width>
[ ".
"
<precision>
]
<conversion-specifier>
<zero-or-space-pad>
::=0
" | "
"Fixed-width, padded formatting. Data from the argument list is converted, but may not occupy more space than specified. If the width of the formatted data is less than the field width, the field is padded to the left with the specified character. If the width of the formatted string is greater than the field width, the result depends on the conversion specifieras follows:
If the conversion specifier is either: 'e', 'E', 'f', or 'F',
i.e. the source data is a real number, then the value of the width is ignored
and all generated characters are accepted. However, the maximum number of
characters can never exceed the value of KMaxRealWidth
.
If the conversion specfier is either 'g' or 'G', i.e. the source
data is a real number, then the value of the width is ignored and all generated
characters are accepted. However, the maximum number of characters can never
exceed the value of KDefaultRealWidth
.
If the conversion specifier is anything else, then the number of converted characters is limited to the width value.
Note that for this formatting conversion, only a zero or a space is permitted for the pad character.
<aligned-conversion>
::=%
"
<alignment>
<pad>
<field-width>
[ ".
"
<precision>
]
<conversion-specifier>
Formatting with alignment, arbitrary pad character and a specified field width. The full aligned-conversion is verbose, but permits characters other than a zero or a space to be used as the padding character. It also permits its value to be aligned within the field.
Undefined terms are discussed below.
Formatted data whose width in characters is less than the width of the field can optionally be aligned to the left, or to the centre of the field. The default is right-alignment.
The alignment specifier is a single character with one of the following values:
|
Data may be formatted into a field with a fixed or a dynamic width. Dynamic field widths require an extra argument.
The field-width specifier is either a sequence
of decimal digits which explicitly define the size of the field to be occupied
by the converted data, or an asterisk ('*
') character. An asterisk
indicates that the size of the field is taken from the next
TUint
value in the argument list.
Formatted data whose width in characters is less than the width of the field can optionally be padded with as many non-blank characters as are needed.
The pad character may be any non-numeric
character. If the pad character is an asterisk ("*
"), then the
next argument in the list is read, interpreted as a TUint
, and
used as the pad character. This feature may be used to pad with asterisk
characters or a digit.
A dot after a field width introduces a precision specifier. This is only useful when formatting real values. Precision specifiers are integers whose decimal values specify the number of decimal places to use when formatting the data.
If the precision specifier is omitted, conversion defaults to
KDefaultPrecision
decimal places.
The conversion of argument data is dictated by the value of the conversion specifier which consists of a single character. The case of this character is significant.
The possible values for conversion-specifier are as follows:
|
Using an asterisk for both field-width and
pad means that the width value and the pad character will be
taken from the argument list. Note that the first '*
' will be
interpreted as representing the width only if it is preceded by one of the
alignment characters '+
' '-
' or
'=
'.
If precision is specified when the data to be converted is not a real number, then it is ignored.