Skip to content

UTL

Introduction

The UTL pre-defined object provides helper utilities.

The UTL object can be used in the SCRIPT attribute and also in the following functions, which are executed after disambiguation:

The UTL object functionalities are exposed through its methods:

  • string_to_number
  • rebase_position

string_to_number

The string_to_number method converts a number expressed in letters in a specified language into numbers and, if necessary, multiplied by a factor.

For example, the following instruction:

var strToNumber = UTL.string_to_number("EN", "onehundredseventyfive", "*M");  

returns the value 175000000 in the string variable strToNumber, that is 175 multiplied by 1000000.

Note

The returned value, even if represented with numbers, is a string.

If the string to be converted is not a number, for example book is passed instead of onehundredseventyfive, the method returns 0.

The syntax is:

UTL.string_to_number(lang, string, adapt);

where:

  • lang is the used language. It can be:
    • EN for English
    • IT for Italian
    • DE for German
    • ES for Spanish
  • string is the number expressed in letters to convert.
  • adapt is the multiplication factor, and it can assumes one the following values:

    Value Multiplication factor
    blank 1
    *K (kilo) 1x103
    *M (mega) 1x106
    *G (giga) 1x109
    *T (tera) 1x1012
    *m (milli) 1x10-3
    *u (micro) 1x10-6
    *n (nano) 1x10-9
    *p (pico) 1x10-12

rebase_position

The rebase_position method is used to rebase the items position (start and end) of a custom output. For example, when an extradata key is returned in output, the position after the processing is not coincident with the source text.

Since Studio works on the text after a clean, the effect of this method isn't directly visible in this environment.

The syntax is:

UTL.rebase_position(index);

where index is the original position index.