INTERFACE CharsTo; (***************************************************************************) (* Copyright (C) Olivetti 1989 *) (* All Rights reserved *) (* *) (* Use and copy of this software and preparation of derivative works based *) (* upon this software are permitted to any person, provided this same *) (* copyright notice and the following Olivetti warranty disclaimer are *) (* included in any copy of the software or any modification thereof or *) (* derivative work therefrom made by any person. *) (* *) (* This software is made available AS IS and Olivetti disclaims all *) (* warranties with respect to this software, whether expressed or implied *) (* under any law, including all implied warranties of merchantibility and *) (* fitness for any purpose. In no event shall Olivetti be liable for any *) (* damages whatsoever resulting from loss of use, data or profits or *) (* otherwise arising out of or in connection with the use or performance *) (* of this software. *) (***************************************************************************) IMPORT Fmt; (* Routines for converting character arrays into numbers/booleans. The routines return a BOOLEAN result indicating whether the conversion succeeded. The result of the conversion is returned via a VAR parameter, which is only updated if the conversion succeeds. A conversion can fail because the given characters are not a valid representation of a number/boolean or because of overflow. Note that there must be no whitespace, whether leading, trailing or embedded in the character array. The case of characters is not significant e.g. "false" and "FALSE" are both valid booleans, "ff" and "FF" are both valid hex numbers *) CONST Decimal = 10; TYPE Chars = ARRAY OF CHAR; PROCEDURE Card( READONLY chars: Chars; VAR c: CARDINAL; base: Fmt.Base := (*Fmt.*)Decimal) : BOOLEAN RAISES {}; (* Convert 'chars' to a cardinal, using the given base *) PROCEDURE Int( READONLY chars: Chars; VAR i: INTEGER; base: Fmt.Base := (*Fmt.*)Decimal) : BOOLEAN RAISES {}; (* Convert 'chars' to an integer, using the given base. 'chars' can start with '+' or '-' or the sign may be omitted entirely *) PROCEDURE Bool(READONLY chars: Chars; VAR b: BOOLEAN): BOOLEAN RAISES {}; (* Convert "TRUE" or "FALSE" into the appropriate boolean *) PROCEDURE BasedCard(READONLY chars: Chars; VAR c: CARDINAL): BOOLEAN RAISES {}; (* Convert a number of the form "base_digits". The base must be specified in decimal and must be in the range given by the type 'Fmt.Base' *) PROCEDURE BasedInt(READONLY chars: Chars; VAR i: INTEGER): BOOLEAN RAISES {}; (* Like 'BasedInt' but allows an optional sign at the start of 'chars' *) PROCEDURE BigCard(READONLY chars: Chars; VAR c: CARDINAL): BOOLEAN RAISES {}; (* Like 'BasedCard' but allows an optional suffix 'k' or 'm'. 'k' multiplies the number by 1024, 'm' multiplies it by 1024 * 1024 *) PROCEDURE BigInt(READONLY chars: Chars; VAR i: INTEGER): BOOLEAN RAISES {}; (* Like 'BigInt' but allows an optional sign at the start of 'chars' *) PROCEDURE Real(READONLY chars: Chars; VAR real: REAL): BOOLEAN RAISES {}; (* Convert 'chars' to a real number. The format of a real number is [+|-]d{d}[.{d}][(e|E)[+|-]d{d}] where 'd' is any decimal digit i.e. an optional sign, then a string of digits optionally containing a decimal point, then an optional e or E followed by an optional sign, followed by an integer. *) PROCEDURE LongReal( READONLY chars: Chars; VAR long: LONGREAL) : BOOLEAN RAISES {}; (* Convert 'chars' to a long real number. The format of a long real is the same as that of a real number *) END CharsTo.