Label

Description

[ShutdownSurvive]
sealed class Tinman.Core.Formatting.Label

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 available:

  • {{ 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:

Public / Constants

Any


public static readonly attribute Any → (Label)

A label that consists of a single placeholder: {0}.

Public / Methods

From


public static method From → (1)

source in : string

[not-null]
The label source code.

returns → Label

The parsed label.

Parses a label.

ValidatingException

If the syntax of source in is invalid.

Public / Attributes

Format


public attribute Format → (get)

value : LabelFormat

The label formatter.

Formats this label with custom tag values.