Label
Description
A label string with format value tags.
The Grammar of a label is as follows:
label := (text | tag)* ;
!tag := '{' '0'..'9'+ expr? '}' ;
text := text-char+ ;
!expr := expr-choice | expr-plural | expr-singular ;
text-char := '{{' | ]{[ ;
expr-choice := '>' argument ('|' argument)* ;
expr-plural := '?' argument ('|' argument)? ;
expr-singular := '!' argument ('|' argument)? ;
!argument := (char+ | '#')* ;
char := ]}#\\|[ | '\\' [}#\\|] ;
Here are some examples:
-
Simple label without tags:
'Hello Mr. Label!' -
Label with simple tag:
'Hello {0} Label!'
with{0} = 'Ms.'evaluates to'Hello Ms. Label!'
Simple tags are replaced by the given values, without applying any further logic. -
Label with conditional tag (three choices):
'Hello {0>Mr.|Mrs.|Ms.} Label!'
with{0} = '1'evaluates to'Hello Mrs. Label!'
Each conditional tag interprets the given value as a zero-based integer index into its list of choices and then gets replaced by the respective choice value. -
Label with conditional tags with choice referencing tag value:
'Found {0>no|one|#} file{0>s||s} in {1>#|one|#} director{1>ies|y|ies}!'
with{0}, {1} = '0'evaluates to'Found no files in 0 directories!'
with{0}, {1} = '1'evaluates to'Found one file in one directory!'
with{0}, {1} = '2'evaluates to'Found 2 files in 2 directories!'
The#in a tag choice will insert the tag value itself. -
Label with singular / plural choice tags:
'Found {0!one|#} file{0?s} in {1!one|#} director{1!y|ies}!'
where{0!one|#}is the compact form of{0:#|one|#}
where{0!one}is the compact form of{0:|one|}
where{0?s|#}is the compact form of{0:s|#|s}
where{0?s}is the compact form of{0:s||s}
with{0}, {1} = '0'evaluates to'Found 0 files in 0 directories!'
with{0}, {1} = '1'evaluates to'Found one file in one directory!'
with{0}, {1} = '2'evaluates to'Found 2 files in 2 directories!'
The following escape sequences are used in the label text:
-
{{as replacement of{ -
}}as replacement of}
The following escape sequences are used in argument expressions:
-
#as replacement of# -
\|as replacement of| -
\}as replacement of} -
\\as replacement of\
For evaluation via Format, tag values are interpreted as integer values according to these rules:
-
LabelFormat.Bool:
true:= 1,false:= 0 -
LabelFormat.Char:
'0':= 0, …'9':= 9 -
LabelFormat.Int:
The value itself. -
LabelFormat.Num:
The rounded value. See Maths.Round. -
LabelFormat.Obj:
null:= 0,1otherwise. -
LabelFormat.Str2:
LabelFormat.Str1:
Fornull, empty and string containing only whitespace characters:0, otherwise1.