SUMMARY: MODULE | CLASS | TYPE | PROC | VAR | CONST | DETAIL: TYPE | PROC | VAR | CONST

# IntConv

### Import List

        ConvTypes

Type Summary
ConvResults = ConvResults One of strAllRight, strOutOfRange, strWrongFormat, or strEmpty.

Procedure Summary
FormatInt(ARRAY OF CHAR): ConvResults Returns the format of the string value for conversion to LONGINT.
LengthInt(LONGINT): INTEGER Returns the number of characters in the string representation of int.
ScanInt(CHAR, VAR ScanClass, VAR ScanState) Represents the start state of a finite state scanner for signed whole numbers--assigns class of inputCh to chClass and a procedure representing the next state to nextState.
ValueInt(ARRAY OF CHAR): LONGINT Returns the value corresponding to the signed whole number string value str if str is well-formed.

Constant Summary
strAllRight The string format is correct for the corresponding conversion.
strEmpty The given string is empty.
strOutOfRange The string is well-formed but the value cannot be represented.
strWrongFormat The string is in the wrong format for the conversion.

Type Detail

### ConvResults

    TYPE ConvResults = ConvResults

> One of strAllRight, strOutOfRange, strWrongFormat, or strEmpty.

Procedure Detail

### FormatInt

    PROCEDURE FormatInt(str: ARRAY OF CHAR): ConvResults

> Returns the format of the string value for conversion to LONGINT.

### LengthInt

    PROCEDURE LengthInt(int: LONGINT): INTEGER

> Returns the number of characters in the string representation of int. This value corresponds to the capacity of an array ``str`' which is of the minimum capacity needed to avoid truncation of the result in the call ``IntStr.IntToStr(int,str)`'.

### ScanInt

    PROCEDURE ScanInt(inputCh: CHAR;
                      VAR chClass: ScanClass;
                      VAR nextState: ScanState)

> Represents the start state of a finite state scanner for signed whole numbers--assigns class of inputCh to chClass and a procedure representing the next state to nextState.

> The call of ``ScanInt(inputCh,chClass,nextState)`' shall assign values to chClass and nextState depending upon the value of inputCh as shown in the following table.

> >     Procedure       inputCh         chClass         nextState (a procedure
> >                                                     with behaviour of)
> >     --
> >     ----       ------       ------        ------ScanInt         space           padding         ScanInt
> >                     sign            valid           SState
> >                     decimal digit   valid           WState
> >                     other           invalid         ScanInt
> >     SState          decimal digit   valid           WState
> >                     other           invalid         SState
> >     WState          decimal digit   valid           WState
> >                     other           terminator      --

> NOTE 1 -- The procedure ScanInt corresponds to the start state of a finite state machine to scan for a character sequence that forms a signed whole number. It may be used to control the actions of a finite state interpreter. As long as the value of chClass is other than Conv.terminator or Conv.invalid, the interpreter should call the procedure whose value is assigned to nextState by the previous call, supplying the next character from the sequence to be scanned. It may be appropriate for the interpreter to ignore characters classified as Conv.invalid, and proceed with the scan. This would be the case, for example, with interactive input, if only valid characters are being echoed in order to give interactive users an immediate indication of badly-formed data. If the character sequence end before one is classified as a terminator, the string-terminator character should be supplied as input to the finite state scanner. If the preceeding character sequence formed a complete number, the string-terminator will be classified as Conv.terminator, otherwise it will be classified as Conv.invalid.

### ValueInt

    PROCEDURE ValueInt(str: ARRAY OF CHAR): LONGINT

> Returns the value corresponding to the signed whole number string value str if str is well-formed. Otherwise, result is undefined.

Constant Detail

### strAllRight

    CONST strAllRight

> The string format is correct for the corresponding conversion.

### strEmpty

    CONST strEmpty

> The given string is empty.

### strOutOfRange

    CONST strOutOfRange

> The string is well-formed but the value cannot be represented.

### strWrongFormat

    CONST strWrongFormat

> The string is in the wrong format for the conversion.