2.6 format
You can define format resources in order to format strings in editable texts and tablefields.
A format resource connects a string as a format description with an optional format function which interprets the string.
Definition
{ export | reexport } format <Identifier> <formatSpec> | <variantDef>
formatSpec ::= <format string> [ <format function> ] ;
variantDef ::= { 0 : <formatSpec> [ <number> : <formatSpec> ] }
If no format function is given, the format string is interpreted internally by the Dialog Manager. If a format function is given, it has to be defined as formatfunc (please see chapter “Format Function” in manual “Rule Language”).
Variants can be used, for example, to make adaptations to different languages.
The following format descriptions are permitted, if the Dialog Manager has to interpret the format string internally:
If the format is an empty string, the input strings will not be formatted.
The following characters are available within the format string:
A |
alphabetic characters |
C |
numbers and uppercase letters |
H |
hexadecimal digits |
N |
digits |
U |
alphabetic characters, only uppercase letters |
X |
any input permitted |
9 |
digits (like N) |
/ |
formatting character |
, |
formatting character |
. |
formatting character |
- |
formatting character |
: |
formatting character |
Space (BLANK) |
formatting character |
The formatting characters are inserted into the display string for display and input. They are skipped during input and thus cannot be overwritten. After the input, they are not adopted in the contents string and are not available there.
Example
Time input:
.format "NN:NN:NN";
Input of 120300
If the format string starts with an "S", the contents string is displayed and edited invisibly.
The character following "S" is interpreted as a special sign for hiding. If no further character is following "S", "*" is chosen as hiding sign. Then, the following format strings are possible:
With hidden formatting, you can e.g. make a password input.
Example
.format "SxAAA";
allows the input of three characters which, however, are all displayed as "x".
allows the formatting of numbers. The format string has to be specified according to the following pattern (element in square brackets [ ] is optional, i.e. it may be left out):
% [<|>] [+|-] [ [0] 0] length [' [sepch] sepcount ] [ ( . | , ) [0] trail ]
[u|s] (b|d|f|h|o|x|X) [<|>] [+|-] [/(c[0]|p|t|z)+]
Meaning of the Various Elements
Remarks
- Leading and trailing zeros are inserted into the display string only. They will not be taken into the content string, not even after the entry has been finished and therefore are not present in it.
- Given a one-digit content string, this digit may not be situated rightmost within the formatted string. Rather it can be the first digit left of the comma, e.g. at technical number input.
-
In an entry field characters that are inserted into the display string by a format cannot be deleted using the Backspace or Del keys.
A sign inserted by a format can be altered using the + and - keys. In doing so + switches to a positive sign or retains it. Entering - toggles between positive and negative sign (just like multiplying by -1).
Availability
A matching expression of the form "/ … /"
is accepted in order to allow the content or input to be validated.
If the content does not match the pattern, an empty string is displayed or the input is prevented.
Examples
-
format FmtKommaZahl "/^(\\d+(\\.\\d*)?)?$/";
Permitted strings e.g. "", "1", "07654.321"
-
format FmtHexZahl "/^[abcdefABCDEF0123456789]*$/";
Permitted strings e.g. "", "AF4513c", "a", "7EF"
-
format FmtSpecial "/^([[:alpha:]]*\n\\d*\n[01]*)?$/";
Permitted strings e.g. "", "City\n999\n01", "Milwaukee\n53288\n01101110"
See also
Built-in function regex() and chapter “PCRE Library for Support of Regular Expressions”.