13.1.2 General Formatting Rules

This chapter discusses the formatting rules for each data type and at the end there is a special section on how to develop new predefined input/output formats for foreign countries. The remainder of this section discusses general rules that apply to all formats.

All formats in C/Base are kept as strings. Within the strings, special characters or key letters are used to define the formatting functions. For the most part, all characters not treated as special are inserted as is into the formatted output (or, on input, must match the input characters literally). The exception to this is boolean values and is discussed in greater detail later.

If a special character is needed as a literal character in the formatted output, the escape character (\) must precede it. For example, in date formats the letter d is special and designates a one or two digit day of the month. The sequence \d inserts the letter d in a formatted result instead of the month. If the escape (\) is wanted in the format, two escape characters must by placed in the format (\\).

Formats for each data type can contain several specifiers: one per range of data values (i.e., positive, negative, zero). These range specifiers are separated by a semicolon (;) character. If a literal semicolon is wanted in the format, the sequence \; must be used.

When ASCII input strings are being converted to binary, the formats are "matched" against the ASCII string. This is the reverse of the process to format the string. For example, when the format specifies a two digit month, the input string must contain two digits which are taken as the month. If the format has an escaped character (\c), the input string must have that character. When a format has several specifiers, each specifier is tried in sequence until one is found that correctly matches the input ASCII string.

If none of the specifiers match, alternate standard input rules are applied to convert the value. These rules provide a standard means of interring data regardless of the output format. Each data type has its own set of rules and these are described in detail in the section on input formats.