1 (* WholeStr.mod implement the ISO WholeStr specification.
3 Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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)
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.
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.
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/>. *)
27 IMPLEMENTATION MODULE WholeStr
;
29 FROM DynamicStrings
IMPORT String
, KillString
, CopyOut
;
30 FROM StringConvert
IMPORT CardinalToString
, IntegerToString
;
31 FROM WholeConv
IMPORT FormatCard
, ValueCard
, FormatInt
, ValueInt
;
34 (* the string form of a signed whole number is
35 ["+" | "-"], decimal digit, {decimal digit}
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.
46 res
:= FormatInt(str
) ;
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. *)
60 s
:= IntegerToString (int
, 0, ' ', int
< 0, 10, FALSE) ;
66 (* the string form of an unsigned whole number is
67 decimal digit, {decimal digit}
70 PROCEDURE StrToCard (str
: ARRAY OF CHAR;
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.
79 res
:= FormatCard(str
) ;
82 card
:= ValueCard(str
)
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. *)
93 s
:= CardinalToString(card
, 0, ' ', 10, FALSE) ;