| 1 |
(* Library module defined by the International Standard |
| 2 |
Information technology - programming languages |
| 3 |
BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language. |
| 4 |
|
| 5 |
Copyright ISO/IEC (International Organization for Standardization |
| 6 |
and International Electrotechnical Commission) 1996-2021. |
| 7 |
|
| 8 |
It may be freely copied for the purpose of implementation (see page |
| 9 |
707 of the Information technology - Programming languages Part 1: |
| 10 |
Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *) |
| 11 |
|
| 12 |
DEFINITION MODULE WholeConv; |
| 13 |
|
| 14 |
(* Low-level whole-number/string conversions *) |
| 15 |
|
| 16 |
IMPORT |
| 17 |
ConvTypes; |
| 18 |
|
| 19 |
TYPE |
| 20 |
ConvResults = ConvTypes.ConvResults; |
| 21 |
(* strAllRight, strOutOfRange, strWrongFormat, strEmpty *) |
| 22 |
|
| 23 |
PROCEDURE ScanInt (inputCh: CHAR; |
| 24 |
VAR chClass: ConvTypes.ScanClass; |
| 25 |
VAR nextState: ConvTypes.ScanState) ; |
| 26 |
(* Represents the start state of a finite state scanner for signed |
| 27 |
whole numbers - assigns class of inputCh to chClass and a |
| 28 |
procedure representing the next state to nextState. |
| 29 |
*) |
| 30 |
|
| 31 |
PROCEDURE FormatInt (str: ARRAY OF CHAR): ConvResults; |
| 32 |
(* Returns the format of the string value for conversion to INTEGER. *) |
| 33 |
|
| 34 |
PROCEDURE ValueInt (str: ARRAY OF CHAR): INTEGER; |
| 35 |
(* Returns the value corresponding to the signed whole number string |
| 36 |
value str if str is well-formed; otherwise raises the WholeConv |
| 37 |
exception. |
| 38 |
*) |
| 39 |
|
| 40 |
PROCEDURE LengthInt (int: INTEGER): CARDINAL; |
| 41 |
(* Returns the number of characters in the string representation of |
| 42 |
int. |
| 43 |
*) |
| 44 |
|
| 45 |
PROCEDURE ScanCard (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass; |
| 46 |
VAR nextState: ConvTypes.ScanState); |
| 47 |
(* Represents the start state of a finite state scanner for unsigned |
| 48 |
whole numbers - assigns class of inputCh to chClass and a procedure |
| 49 |
representing the next state to nextState. |
| 50 |
*) |
| 51 |
|
| 52 |
PROCEDURE FormatCard (str: ARRAY OF CHAR): ConvResults; |
| 53 |
(* Returns the format of the string value for conversion to CARDINAL. |
| 54 |
*) |
| 55 |
|
| 56 |
PROCEDURE ValueCard (str: ARRAY OF CHAR): CARDINAL; |
| 57 |
(* Returns the value corresponding to the unsigned whole number string |
| 58 |
value str if str is well-formed; otherwise raises the WholeConv |
| 59 |
exception. |
| 60 |
*) |
| 61 |
|
| 62 |
PROCEDURE LengthCard (card: CARDINAL): CARDINAL; |
| 63 |
(* Returns the number of characters in the string representation of |
| 64 |
card. |
| 65 |
*) |
| 66 |
|
| 67 |
PROCEDURE IsWholeConvException (): BOOLEAN; |
| 68 |
(* Returns TRUE if the current coroutine is in the exceptional execution |
| 69 |
state because of the raising of an exception in a routine from this |
| 70 |
module; otherwise returns FALSE. |
| 71 |
*) |
| 72 |
|
| 73 |
END WholeConv. |