SFormat

SFormat

The SFormat is a super BFormat. It provides additional features to navigate through components & relations, read tags, modify text (escape, substring, etc) and so on.

A SFormat is defined by a chain of characters between curly brackets { } and is a succession of functions used to build the result. Unlike the BFormat, the SFormat result can be a component or any object (while BFormat can only result in a String).

Example: {parent.relations('out','b:isIn').item(1).%displayName%}  -> Take the parent, then follow its outbound relations b:isIn, then take the second element (because there might be several relations) and then apply the BFormat to get the displayName.



Functions in a SFormat can take parameters between parenthesis and separated by a coma. It can take one of the following parameters depending on the function:

  •  

    • String: 'param'

    • Number: 3 or 6.4

    • Boolean: true or false



SFormat is used in Active components such as InfoSource, HistoryDisplayName management and is mainly used in Strategies.
Example: {parent.inRel('b:isIn')}

Classic BFormat can be defined between %...% (as usual). It can be introduced after the definition of a component by SFormat functions or directly at the root as a classic BFormat.
Example: {parent.inRel('b:isIn').%displayName%}

If you want to avoid interpretation of SFormat, you can use [...], so the format will not be resolved.
Example: station:|slot:|bql:select slotPathOrd, displayName, [btibCore:BqlLib.sFormat('{origin.inRel(b:strSourceOf).parent.%slotPathOrd%}')] from btibStructure:Node where b:floor = '{origin.%displayName%}' will result in: station:|slot:|bql:select slotPathOrd, displayName, btibCore:BqlLib.sFormat('{origin.inRel(b:strSourceOf).parent.%slotPathOrd%}') from btibStructure:Node where b:floor = 'Floor 1' 



Here is the list of the functions currently implemented by the SFormat.
Recently added functions are highlighted in blue.

Name

Description

Base Type

Parameters

Return Type

Name

Description

Base Type

Parameters

Return Type

parent

Get the parent of a component.

Component

-

Component

children

Get the children of a component.

Component

-

Array

slot

Get a slot of a component.

Component

  • Slot name

Object

child

Deprecated. This function is now called 'slot'.

Component

  • Child name

Object

length

Get the size of an array or of a String.

Array

-

Number

item

Get the item of an array at a given index. Index starts at 0.

Array

  • Index of the item

Object

first

Get the first item of an array.

Array

-

Object

last

Get the last item of an array.

Array

-

Object

removeFirst

Remove the first item of the array return the array.

Array

-

Array

removeLast

Remove the last item of the array return the array.

Array

-

Array

removeDuplicates

Remove the duplicates from an array.

Array

-

Array

filter

Filter the values of an array. Value is valid if equals to the given String, boolean or double.

Array

  • Value of the value to filter

Array

display

Convert an array into a String using a format. Format is applied to each value of the array. Use [] to protect SFormat from resolve. Use \n for line break.

Array

  • Format to apply

String

ord

Execute a query: slotPathOrd, bql or neql. Base: absolute or relative.

Component

  • Query

Array

escape

Escape a String.

String

-

String

unescape

Unescape a String.

String

-

String

toFriendly

Convert a String to friendly case.

String

-

String

fromFriendly

Convert a String from friendly case.

String

-

String

fileName

Replace special chars (including accents) by _

String

-

String

safeName

Stripe accents and replace special chars by _

String

-

String

substring

Reduce a String between two indexes.

String

  • Start index

  • End index

String

substringFromEnd

Remove x characters from a String, starting at the end.

String

  • Number of chars to remove

String

indexOf

Return the index of an input String.

String

  • String to match

Number

replace

Replace an input String in the base.

String

  • String to replace

  • String of replacement

String

prefix

Will return the prefix followed by the base if the base is not null or empty.

String

  • Prefix

String

suffix

Will return the base followed by the suffix if the base is not null or empty.

String

  • Suffix

String

split

Split a String depending on a sequence of chars.

String

  • String to split at

Array

splitRegex

Split a String depending on a regex.

String

  • Regex to split at

Array

orEmpty

Will return the base if the base is not null or empty.

String

-

Boolean

toDynamicEnum

Convert an array into a value to a dynamic enum.

Array

-

DynamicEnum

toDynamicEnums

Convert an array of x elements into an array of x enums with only one value.

Array

-

DynamicEnums

toString

Convert the base in a String.

Object

-

String

toInt

Convert the base in an integer.

Object

-

Number

toDouble

Convert the base in a double.

Object

-

Number

toOrd

Convert the base in an ord.

Object

-

Ord

toBrush

Convert the base in a brush.

Object

-

Brush

toTag

Get the tag of the value of an enum.

Object

-

String

toDisplayTag

Get the display tag of the value of an enum.

Object

-

String

toSimple

Convert the base in a Simple.

Object

  • Type of the Simple (ex: baja:Color)

Simple

add

Add a number to another.

Number

  • Number to add to base

Number

subtract

Subtract a number to another.

Number

  • Number to subtract from base

Number

multiply

Multiply a number to another.

Number

  • Number to multiply base

Number

divide

Divide a number to another.

Number

  • Number to divide vase

Number

pxView

Get the ord of the file of a pxView.

Component

  • Name of the px view

  • OR Index of the px view

  • OR nothing (will take first view)

Ord

isType

Return whether a component is from the given type or not.

Component

  • Type (ex: baja:Folder)

Boolean

checkType

Return the base if it's from the given type.

Component

  • Type (ex: control:ControlPoint)

Boolean

makeType

Create a new instance of a type.

Component

  • Type (ex: control:BooleanWritable)

Object

exists

Return whether an object/slot exists, i.e. is not null.

Object

-

Boolean

isNull

Return whether an object is null. Also see isInvalid() function.

Object

-

Boolean

isEmpty

Return whether an array is empty.

Array

-

Boolean

isInvalid

Return whether an object is null or a String is equals to "null", is empty or contains "err:".

String

-

Boolean

property

Get a property of a component identified by its name. Property includes name, value, flags and facets.

Component

  • Name of the property

Object

properties

Get all the properties of a component. Property includes name, value, flags and facets.

Component

-

Array

frozenProperties

Get all the frozen properties of a component. Property includes name, value, flags and facets.

Component

-

Array

dynamicProperties

Get all the dynamic properties of a component. Property includes name, value, flags and facets.