Loading...
 

FString

FString

FString(editMask, constantText), FString(STACK, STACK ).

Stack
StackPositionTypeDescription
Stack(In)TopSTRINGInput
Stack(Out)TopSTRINGFormatted output

This command implements the formatting function used internally by the FormattedString widget.

This formatting function translates arbitrary strings into a corresponding formatted string. The formatting is defined via the parameters editMask and constantText . If editMask is empty, then no formatting is applied and the string is returned exactly the same.

The FString function maps unformatted strings into a space of formatted strings (defined by editMask and constantText). Strings that are already formatted are not changed by this function. The function is thus idempotent, which is an important property of the FString function, so that executing PutValue&GetValue or FillWindow&DrainWindow on a FormattedString widget does not change an already formatted value again, as the value should only change if the user has made an input or the format has changed. The need for the idempotency of this function also explains some somewhat strange rules when processing the editMask.

Note: The behaviour described here corresponds to the behaviour as of Dll version 224610. Before that, FString was not idempotent and the semantics were not clearly defined. The behaviour of the following editMask characters has changed as a result 0,#,K,L,N.

Functionality

The editMask defines at which position in the input/output what kind of characters are expected and thus also the maximum length of the formatted string. The formatted string is never longer than the editMask.

The input string is formatted by going through the editMask character by character and, depending on the mask character, starting from the last position, searching for a corresponding character in the input and taking it over into the output text. For each character that is read in the editMask, a corresponding character is also read from the constantMask at the same position. The constantMask should therefore have the same length as the editMask. The characters from the constantMask are read in the FString command only for the mask k,K.

In the FormattedString widget, the constantMask is used to define the text that is to be inserted in place of the deleted characters when they are deleted. Accordingly, the constantMask should always represent a valid input for the editMask.

When searching for a suitable character, it can also happen that the input no longer contains a suitable character. The input position is then placed at the end of the input and all subsequent elements of the editMask behave as described in the table in the column "if empty".

Mask character

Maskaccepts input charactergenerated outputif empty1
Simple formats
aBlank or letter (A...Z or a...z respectively)The character a from the input""
ABlank or letter (A...Z or a...z respectively)The character from the input as a capital letter""
cBlank, letter (A...Z or a...z) or digit (0...9)The character from the input""
CBlank, letter (A...Z or a...z) or digit (0...9)The character from the input as a capital letter""
n, Ndigit (0...9)The digit from the input2"0"
xany printable characterThe character from the input""
Xany printable characterThe character from the input as a capital letter""
Extended formats
k, KThe character from constantText at the current position.
This mask does NOTsearch the input3
The corresponding character from constantTextThe corresponding character from constantText
0...0A sequence of digits with 0 to n digits
n = number of 0's
The digit sequence of the input on the left padded with zeros to a length of n digits.n 0's
#...#Sequence of digits with 0 to n digits, which may be preceded by spaces.
The preceding spaces count towards the number of digits.4
n = number of # characters
The sequence of digits of the input on the left is padded with spaces to a length of n characters.(n-1) Space followed by a 0.
Placeholder
l, LThis mask is simply read over in the editMask and constantMask.
This does not change the position in the input text.5
""""

1="" here means that nothing is written to the output and "0" means that only a 0 is written to the output.

2= Since N still produces an output if the input is empty, it is potentially executed multiple times (see special rule K&N).

3= This means that the input position is advanced by one character if the current character of the input matches the character current character from constantText . If this is not the case, the input position is not changed. In both cases, however, the same output is produced. (See special rule K)

4= The blanks must be counted in the mask "####" so that the function is idempotent. Otherwise, the mask "##0" with the input "1" would first generate the output " 10" and, when executed again, the output "100".

5= This placeholder is used by the FormattedString widget to insert the corresponding placeholder from constantText at this position in the text field. However, this placeholder is never included in the output.

Explanation of special rules

mask k,K

The mask K always writes the character from the current position in constantText into the output. If this character also matches the current character from the input, then the position in the input is advanced by one place. Otherwise, the input position is not changed (in contrast to A,C,N&X, the input is not searched for the character).

This special treatment is necessary for FString to be idempotent.
Example:

"ab123"  FString("AAKNNN", "AA-000") //= "AB-123"
"AB-123" FString("AAKNNN", "AA-000") //= "AB-123"


If K would never advance the input, then the second application in the example would have resulted in "AB--123".
If K would search the input, then the first application in the example would have resulted in "AB-000".

There is no difference between using k and K. In both cases, the character is taken 1:1 from the constantMask.

Implicit multiple use of k,K and n,N.

Since the masks A,C,X do not produce any output if the input is empty, the mask K and N can extend the output string, since an output is generated even if the input is empty. By clever combination with other masks, a format can thus be defined which, in the case of an empty input, would only produce a fully formatted text after multiple applications of FString, which no longer changes. Since FString must be idempotent, such cases are recognised and FString is called again internally on the result.

Examples:

"" FString("XXXK", "...F")       //= "FFFF"    ("" ⟶ "F" ⟶ "FF" ⟶ "FFF" ⟶ "FFFF")
"" FString("XXKXXKK", "..A..BC") //= "ABACBBC" ("" ⟶ "ABC" ⟶ "ABACBC" ⟶ "ABACBBC")
"" FString("XXXN", "...0")       //= "0000"    ("" ⟶ "0" ⟶ "00" ⟶ "000" ⟶ "0000")

mask #...#

The mask "#" defines a formatting field that accepts 0-n digits, where n corresponds to the number of # characters. If such a field is reached in the editMask, then all characters in the input that are not digits or spaces are skipped. Then leading spaces are read in from the input text (are treated like leading 0's) and then the digits themselves. The leading spaces are treated like 0's and are also counted in the number of digits.

This behaviour differs from the mask "0...0", which works very similarly, but skips leading blanks completely and does not count them among the digits. However, this distinction is necessary for FString to be idempotent. As soon as a real digit is found, all characters that are not digits are counted as the end of the input for this field.

Examples:

"1"       FString("###000", "000000") //= "  1000"
"  1000"  FString("###000", "000000") //= "  1000"
"1"       FString("000###", "000000") //= "001  0"
"001  0"  FString("000###", "000000") //= "001  0"
"123 456" FString("###000", "000000") //= "123456"
"123 456" FString("000###", "000000") //= "123 45"

If #...# leading spaces did not count as digits, then the format "##0" with the input "1" would first return " 10" and, when executed again, "100".

Mask l,L

The mask L (and the corresponding character from the constantText) is completely ignored when using this formatting function. L defines a placeholder that is only observed by the FormattedString widget and ensures that the character from the constantText is displayed as a placeholder in the widget at this point. This placeholder only serves as a guide for the input and with GetValue the placeholder created by L is not returned and with PutValue it is also not expected in the input.

Since L , in contrast to K, is completely read over, the explicit specification of the placeholder in PutValue ensures that the input is sometimes not interpreted as expected by the user.

Example:

"CB-123" FString("AALNNN", "AA-000") //= "CB123"
"CB-123" FString("AALXXX", "AA-...") //= "CB-12"

If L were to read over the placeholder in the input, if it occurs in it, then FString("LAA", "AAA") would progressively shorten the input "AAA" to "", which is not the behaviour of a placeholder used only for representation within.

Examples

Input stringeditMaskconstantTextResult string
"abc123XQW5%&#$!_*~""""abc123XQW5%&#$!_*~"
"1078""K0000""S0000""S1078"
"C-12ab""AK00000"".=""C=00012"
"b12ab""AK00000"".=""B=00012"
"123""00000""00000""00123"
"12345""NNKNNKNN""00-00-00""12-34-50"
"1234567""XXXXKXXKXXX""....-..-..-...""1234-56-7––"
"B12""AK0000"".-""B-0012"
"12co""0000LAA""0000-AA""0012CO"
"12co""0000KAA""0000-AA""0012-CO"
"B12""AK####"".-""B- 12"
"123456""000K00K00""...-..-..""123-45-06"
"1234560"000K00K00""...-..-..""123-45-60"
"HALLO23""AAAAAAA"".......""HELLO"
"Y23""XXK000""EB-123""Y2-003"
"Y23""AAK000""EB-123""Y-000"
"CD23""AAK000""EB-123""CD-023"
"AB""x000x""""A000"
"""XXKXXKK""..A..BC""ABACBBC"
"""XXXN""...0""0000"
"ABAA""LAAA""AAAA""ABA"
"""KK0000""23""230000"
"1""KK0000""23""230001"
"230000"k
"230001"k