]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/gm2-libs-iso/WholeStr.mod
Merge modula-2 front end onto gcc.
[thirdparty/gcc.git] / gcc / m2 / gm2-libs-iso / WholeStr.mod
1 (* WholeStr.mod implement the ISO WholeStr specification.
2
3 Copyright (C) 2008-2021 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
26
27 IMPLEMENTATION MODULE WholeStr ;
28
29 FROM DynamicStrings IMPORT String, KillString, CopyOut ;
30 FROM StringConvert IMPORT CardinalToString, IntegerToString ;
31 FROM WholeConv IMPORT FormatCard, ValueCard, FormatInt, ValueInt ;
32
33
34 (* the string form of a signed whole number is
35 ["+" | "-"], decimal digit, {decimal digit}
36 *)
37
38 PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER;
39 VAR res: ConvResults);
40 (* Ignores any leading spaces in str. If the subsequent
41 characters in str are in the format of a signed whole
42 number, assigns a corresponding value to int. Assigns
43 a value indicating the format of str to res.
44 *)
45 BEGIN
46 res := FormatInt(str) ;
47 IF res=strAllRight
48 THEN
49 int := ValueInt(str)
50 END
51 END StrToInt ;
52
53
54 PROCEDURE IntToStr (int: INTEGER; VAR str: ARRAY OF CHAR);
55 (* Converts the value of int to string form and copies
56 the possibly truncated result to str. *)
57 VAR
58 s: String ;
59 BEGIN
60 s := IntegerToString(int, 0, ' ', TRUE, 10, FALSE) ;
61 CopyOut(str, s) ;
62 s := KillString(s)
63 END IntToStr ;
64
65
66 (* the string form of an unsigned whole number is
67 decimal digit, {decimal digit}
68 *)
69
70 PROCEDURE StrToCard (str: ARRAY OF CHAR;
71 VAR card: CARDINAL;
72 VAR res: ConvResults);
73 (* Ignores any leading spaces in str. If the subsequent
74 characters in str are in the format of an unsigned
75 whole number, assigns a corresponding value to card.
76 Assigns a value indicating the format of str to res.
77 *)
78 BEGIN
79 res := FormatCard(str) ;
80 IF res=strAllRight
81 THEN
82 card := ValueCard(str)
83 END
84 END StrToCard ;
85
86
87 PROCEDURE CardToStr (card: CARDINAL; VAR str: ARRAY OF CHAR);
88 (* Converts the value of card to string form and copies the
89 possibly truncated result to str. *)
90 VAR
91 s: String ;
92 BEGIN
93 s := CardinalToString(card, 0, ' ', 10, FALSE) ;
94 CopyOut(str, s) ;
95 s := KillString(s)
96 END CardToStr ;
97
98
99 END WholeStr.