Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.5d

Application v 5.25a

  

 

Chapter FiveGeneral Functions (continued)

5.2 String Functions

5.2.1 Overview

A major part of this chapter covers a large group of functions dealing with strings, including output, parsing, and other fundamental functionalities.

A string is a series of characters normally terminated by a zero byte (/0 or 0x00). The characters can be virtually anything but typically represent text or some type of coded text. For example:

“My name is Bob”

is represented as a series (or string) of coded characters:

M  y     n  a  m  e     i  s     B  o  b

4D 79 20 6E 61 6D 65 20 69 73 20 42 6F 62 00

Each of the characters is represented by an ASCII code, and the string is ended with a zero-byte or terminator. This is conventional for most languages and is produced and is expected by most Legato functions unless otherwise specified. Any string data placed after the zero-byte will generally be ignored.

5.2.2 Strings

Since Legato supports an application that is largely designed to process text and tables, it is only natural that we start with strings. Strings are either a series of 8-bit or 16-bit characters. What you are reading is text within a paragraph which is represented by a series of characters that are then grouped and said to be in a string. For most languages, strings are what is typically known a “zero-terminated”. This means the end of series of characters is denoted by a zero byte (0x00 or simple code 0). Strings can also be constrained by a size, but this is not the norm. Unless otherwise noted, all strings are assumed to be zero-terminated. See Section 3.5 Strings Versus Characters for more details on strings and characters.

Typically strings employ 8-bit characters for ASCII, ISO-8851 and ANSI sets. Unicode requires 16-bit or ‘wide’ strings.

Note: Unicode support is very limited in Version 1.1 of Legato.

5.2.2.1 Formatted Strings

Most languages provide a method to format data into presentable string arrangements for human or computer consumption, and Legato is no exception. Formatted strings can be employed as part of a number of functions, including the FormatString, AddMessage , and MessageBox functions. For example, the following code:

MessageBox("%d items processed, %d errors", items, errors);

will yield something like this (depending on the values of items and errors):

Functions employing formatted strings will automatically convert both the variable type and formatting of the string content. For example, if a string is requested to be inserted and a floating-point number is provided as a parameter, the floating-point number will be converted to a string with formatting as specified and then inserted.

Formatted strings contain effectively two types of data: inert characters that are passed through and control segments that are replaced with formatted content. The source string is directly copied to the result until a ‘%’ character is encountered, at which point the conversion process replaces the content. Inert or ordinary characters are like any other string literal within the language. When a ‘%’ character is desired in the output, add ‘%%’ which will be replaced by a single character.

The control segments start with the ‘%’ character and end with a specific format character (detailed in the next section). C/C++ programmers will recognize this coding style since the underlying formatting function uses the C++ libraries. In between, optional formatting information can be added. For example:

%dconverts a numeric parameter (or converted string) to a string character representation of that number.
%3dconverts the integer but will pad up to two spaces leading the number.
%03dpads with leading zeros.

The basic format is:

% flags size type

Where:

Flags — One or more characters, in any order, which modify the control segment:

-Specifies a left adjustment to the converted segment.
+Specifies that the number will always be converted with a +/- sign (does not apply to strings, accounting or hex).
0Specifies to fill with zeros rather than spaces.
#Specifies an alternative output form. For ‘o’ (octal), the first digit will always be zero. For ‘x’ or ‘X’ (hex), a leading prefix is added as 0x. For floating-point (‘e’ ,’E’, ‘f’, ‘g’ and ‘G’), the output will always have a decimal point; for ‘g’ and ‘G’, trailing zeros will not be deleted.

Size — A number specifying a minimum field width. The converted segment will be created to be at least this wide and wider if required. If the resulting field contains less characters, it will be padded left or right as necessary to fill the size requirement. The padding character is normally a space but can optionally be a zero if the size is specified with a leading 0.

A period character within size separates the integer size from the precision for floating-point format. For example, %2.1f will always have a trailing .1 precision. See type next for more information.

Type — A character dictating the type of formatting to be applied. The following types are permitted:

dSigned decimal integer (“0, 5, -1” for compatibility with C).
iSigned decimal integer (“0, 5, -1”).
oOctal (“1”).
xHexadecimal lower (“1a0e”).
XHexadecimal upper (“1A0E”).
uUnsigned decimal integer (“1”).
cCharacter (“a”).
s

String (“hello”). String fields may have one component for formatting:

%ns   or   %-ns

Where n is the overall field size in characters. By default, the field is right aligned in the character padding area. Adding a leading dash will left align the data.

fFloat (“1.2”). Note that the default precision for floating point values is 6 digits. To achieve a higher level of translation of precision, use explicit numeric format values. For example, ‘%1.10f”.
eScientific lower (“1.2e+3”).
EScientific upper (“1.2E+3”).
gUse the shortest representation: %e or %f (“123.45”).
GUse the shortest representation: %E or %F (“123.45”).
a

Accounting (“12,345”). If the number is negative, the value is placed inside of parenthesis, for example, -12345 becomes “(12,345)”. For padded fields such as “%15a”, the last character is reserved as either a space or close parenthesis for alignment purposes. The provides for easy alignment of text fields.

Accounting fields may have one component for formatting of integer values:

%na   or   %-na

Where n is the overall field size in characters. By default, the field is right aligned in the character padding area. Adding a leading dash will left align the data.

For float values, the accounting field as an additional component:

%n.pa   or   %-n.pa

Where n is as described above and p is the number of decimal places. If p is omitted, the default value is 2.

A

Accounting (“12,345”). If the number is negative, a dash is placed in front of the value, for example, -12345 becomes “-12,345”. For padded fields such as “%15a”, the last character is reserved as either a space or close parenthesis for alignment purposes. The provides for easy alignment of text fields.

Accounting fields may have one component for formatting of integer values:

%na   or   %-na

Where n is the overall field size in characters. By default, the field is right aligned in the character padding area. Adding a leading dash will left align the data.

For float values, the accounting field as an additional component:

%n.pa   or   %-n.pa

Where n is as described above and p is the number of decimal places. If p is omitted, the default value is 2.

 

The number of control segments must match the number of provided parameters.

5.2.3 String and String Related Functions

The following sections cover basic strings:

Section 5.3 String Tester Functions — Basic string functions for testing string content.

Section 5.4 Basic String Functions — Basic string functions for manipulating string content.

Section 5.6 Numeric String Processing — Functions for the processing of numeric data as strings and numbers as binary data.

Section 5.7 Tabs and Tab Characters — Processing and dealing with tab characters.

Section 5.8 Word Parsing — A series of functions surrounding the Word Parse Object to perform fast parsing.

Section 5.9 String Pool Functions — Functions to support large string objects for reading, writing, and organizing data.

Section 5.12 Date and Time Functions — Functions to support date and time both in string and binary formats.