Built-in functions

Built-in functions are the functions that come with EFX: they convert, test, compute and format values. You call them by name, with their arguments in parentheses, for example count(BT-13-Text) (see Built-in function call). This page groups the functions by category, explains how their entries are laid out, and lists them in alphabetical order. For the functions that you declare yourself, in template files, see User-defined function call.

Categories

The categories group the built-in functions by the kind of value that they give or work on. When a function would fit several categories, its entry is in one of them, and the others mention it.

Category Functions

Conversion functions

text, number, indicator, date, time, day-time-duration, year-month-duration

Text functions

string-length, index-of-substring, substring, substring-before, substring-after, concat, string-join, repeat, upper-case, lower-case, capitalize-first, normalize-space, trim, trim-left, trim-right, pad-left, pad-right, replace, replace-regex, url-encode

Numeric functions

absolute, round, round-down, round-up, sum, min, max, average

Indicator functions

not, contains, starts-with, ends-with, empty, sequence-equal

Date, time and duration functions

current-date, current-time, add-duration, subtract-duration, year, month, day, hours, minutes, seconds, years, months, days

Sequence functions

count, count-duplicates, distinct-values, get-duplicates, value-union, value-intersect, value-except, sort, reverse, subsequence, index-of, split

Template-only functions

format-number, format-short, format-medium, format-long, preferred-language, preferred-language-text

You can use the functions of the last category in template files only. You can use all the other functions everywhere: in single expressions, in template files and in rules files.

You write many tests and calculations with operators rather than functions, for example is present, in, like, + and == (see Operators). For the patterns that like and replace-regex use, see Regular expressions.

How entries are presented

Each function has one entry. The anchor of the entry is fn- followed by the name of the function. An entry gives:

  • the purpose of the function;

  • its syntax and its parameters;

  • a description of what it does;

  • its restrictions;

  • examples;

  • the differences from EFX-1;

  • related entries.

The syntax shows each form of the function on its own line, as a signature, that is, the name of the function, its parameters and the type of its result:

substring(<text>, <start>) → text
substring(<text>, <start>, <length>) → text

The placeholders in angle brackets stand for the arguments, and the type after the arrow is the type of the result. The list below the syntax gives the type and the meaning of each argument, and says which arguments are optional. The types are the EFX data types: text, number, indicator, date, time and duration (see Data types). A star marks a sequence: text* is a sequence of texts.

Some functions, such as sort, accept a sequence of any data type. Their syntax calls the argument <sequence> and the result sequence, which means a sequence of the same type as the argument. When a function has several forms for different types, such as text, the translator chooses the form from the types of the arguments.

The following rules apply to all built-in functions:

  • You write function names in lower case. COUNT and Count are not names of functions.

  • An argument can be any expression of the required type: a literal, a field reference, a variable, a call to another function or a calculation. An argument of the wrong type is an error, which the translator reports when it translates the expression (see Type checking).

  • A parameter described as a single value (scalar) cannot receive a sequence. In particular, a field that can have several values from the context, such as a repeatable field, is an error there. Each entry says which parameters take a sequence.

  • A parameter that takes a sequence also accepts a single value, as a sequence of one value.

  • Several entries describe what happens when an argument "has no value", for example a field that is not present in the notice. Each entry gives the result in that case.

  • Some errors depend on the data, so EFX can find them only when the expression is applied to a notice. An example is a text that is not a valid date, given to date. The entries name these errors.

Unless an entry says otherwise, its examples are expressions read from the root of the notice, ND-Root. The examples of template-only functions are complete template lines.

A note labelled "EFX-1" says whether the function is new in EFX-2 or has changed. A function without such a note works as in EFX-1.

Alphabetical list

Function Purpose

absolute

Absolute value of a number.

add-duration

Adds a duration to a date.

average

Arithmetic mean of a sequence of numbers.

capitalize-first

Converts the first character of a text to upper case.

concat

Joins texts into one text.

contains

Tests whether a text contains another text.

count

Number of values in a sequence.

count-duplicates

Number of values in a sequence that repeat an earlier value.

current-date

The current date.

current-time

The current time.

date

Converts a text to a date.

day

Day of the month of a date.

day-time-duration

Converts a text to a duration in days, hours, minutes and seconds.

days

Number of whole days in a duration.

distinct-values

The values of a sequence without duplicates.

empty

Tests whether a text has no characters.

ends-with

Tests whether a text ends with another text.

format-long

Formats a date or a time in a long form (templates only).

format-medium

Formats a date or a time in a medium form (templates only).

format-number

Formats a number following a picture (templates only).

format-short

Formats a date or a time in a short form (templates only).

get-duplicates

The values that occur more than once in a sequence.

hours

Hours of a time.

index-of

Position of a value in a sequence.

index-of-substring

Position of a text inside another text.

indicator

Converts a number to an indicator.

lower-case

Converts a text to lower case.

max

Largest number of a sequence.

min

Smallest number of a sequence.

minutes

Minutes of a time.

month

Month of a date.

months

Total number of months in a duration.

normalize-space

Removes the white space at the start and end of a text, and reduces each run of white space inside it to one space.

not

Negates an indicator.

number

Converts a text or an indicator to a number.

pad-left

Adds characters at the start of a text up to a given length.

pad-right

Adds characters at the end of a text up to a given length.

preferred-language

Language of the best-suited value of a multilingual text field (templates only).

preferred-language-text

Best-suited value of a multilingual text field (templates only).

repeat

Repeats a text a given number of times.

replace

Replaces every occurrence of a text by another text.

replace-regex

Replaces every part of a text that matches a regular expression.

reverse

The values of a sequence in reverse order.

round

Rounds a number to the nearest whole number.

round-down

Rounds a number down to a whole number.

round-up

Rounds a number up to a whole number.

seconds

Seconds of a time.

sequence-equal

Tests whether two sequences contain the same values, in any order.

sort

The values of a sequence in ascending order.

split

Splits a text into a sequence of texts.

starts-with

Tests whether a text begins with another text.

string

Another name for text.

string-join

Joins the texts of a sequence, with a separator.

string-length

Number of characters in a text.

subsequence

Part of a sequence.

substring

Part of a text.

substring-after

Part of a text after a delimiter.

substring-before

Part of a text before a delimiter.

subtract-duration

Subtracts a duration from a date.

sum

Total of a sequence of numbers.

text

Converts a number, an indicator, a date, a time or a duration to text.

time

Converts a text to a time.

trim

Removes the white space at the start and end of a text.

trim-left

Removes the white space at the start of a text.

trim-right

Removes the white space at the end of a text.

upper-case

Converts a text to upper case.

url-encode

Encodes a text for use in a web address.

value-except

The values of a sequence that do not occur in another.

value-intersect

The values that occur in both of two sequences.

value-union

The values that occur in either of two sequences.

year

Year of a date.

year-month-duration

Converts a text to a duration in years and months.

years

Number of whole years in a duration.