GoFiler Legato Script Reference
Legato v 1.5d Application v 5.25a
|
Table of Contents | < < Previous | Next >> |
Chapter Three — Data Types and Operators (continued)
String literals represent string data within the source code of the script. String literals can declared as 8-bit or 16-bit character sequences. 8-bit strings can contain all characters, including control sequences. While the default is to process escaped characters, a raw version may also be declared. 16-bit string literals, also known as wide strings, may also be declared. However, since Legato only accepts ANSI source files, any characters above 255 must be encoded within the string.
It is the programmer’s responsibility to track and manage the encoding of string literals.
String literals are automatically null terminated.
String literals are defined as text in between open and close quotation marks. For example:
string s1;
s1 = "Hello, world!";
The quotation marks are not considered part of the string. In order to use quotation marks and control characters within a string literal, they must be properly escaped. Also note that these are straight quotes " not “ or ” (147 and 148).
Adding “L” as a prefix makes the string a wide string or Unicode (“L” comes from other languages such as C++). The resulting literal string is treated line a wstring data type.
wstring w1;
w1 = L"Hello, world!";
Note that the native file format for source code is the ANSI (Windows 1152) character set. As such, declaring a wide string and adding ANSI characters will convert characters above 127 to Unicode positions. Manually escaped character values are not converted.
The following escaped control characters are allowable within a string or wstring literal:
\\ | 0x7C | Slash |
\? | 0x3F | Question (C compatibility) |
\" | 0x22 | Escaped double quote |
\' | 0x27 | Escaped single quote |
\a | 0x07 | Alert |
\b | 0x08 | Backspace |
\f | 0x0c | Form Feed |
\n | 0x0A | New Line |
\r | 0x0D | Return |
\t | 0x09 | Tab |
\u | nnnn | Four char Unicode value |
\v | 0x0B | Vertical Tab |
\nnn | nnn | Octal Code (\0) |
\xnn | nn nnnn | Hex Code (8 or 16 bit) |
Null termination (zero-termination) characters can also be placed within the string literal with the ‘\0’ code. For 8-bit strings, the hex value must be a 2 character group such as 1c or d2. For 16-bit literals, the hex can be variable length. For example, "\x0dMyReturn" stopped hex processing on the letter ‘M’ while "\xdacat" will stop on the letter ‘t’ resulting in an ambiguous string. To resolve this, code the literal as 4 character hex code "\x00dacat". Hex codes must be lowercase for 16-bits strings.
Raw, or unescaped strings may also be declared using the “R” prefix:
string s1;
s1 = R"D:\Documentation\Legato\03100_Literal_String_Data.htm";
In this case the backslash escape character “\” is not processed. Note that the string cannot contain a double quote as a simple character. To embed a double quote, add in “\042” or “\x22” as the character value.
String literals are commonly used with assignment, concatenation, and logical comparisons operators. Comparing two strings for equality (with either comparison operators or string comparison functions) can lead to undesirable results due to the presence of control and escape characters that may be difficult to detect, so programmers are encouraged to use caution.
There are many methods for representing line endings and moving data between applications or platforms is made more difficult and tedious because of it. Within the operating environment, all the ending methods are universally accepted for input. For output, the developer must determine the type of endings to use.
For example, Windows:
This is a line\r\n
Apple Mac:
This is a line\r
Some Linux systems:
This is a line\n
The decision should be made with respect to the system on which the data must be displayed and read. Legato offers numerous string functions to help determine which line endings are present within a string and options for conversion between the different types.
In general, functions that retrieve data as a line, such as ReadLine, will read the line of data and remove the actual line ending character(s). Likewise, various functions that write lines will add the line endings with options for setting the type of line ending characters to be used.
Table of Contents | < < Previous | Next >> |
© 2012-2024 Novaworks, LLC. All rights reserved worldwide. Unauthorized use, duplication or transmission prohibited by law. Portions of the software are protected by US Patents 10,095,672, 10,706,221 and 11,210,456. GoFiler™ and Legato™ are trademarks of Novaworks, LLC. EDGAR® is a federally registered trademark of the U.S. Securities and Exchange Commission. Novaworks is not affiliated with or approved by the U.S. Securities and Exchange Commission. All other trademarks are property of their respective owners. Use of the features specified in this language are subject to terms, conditions and limitations of the Software License Agreement.