1 /* do not edit automatically generated by mc from StringConvert. */
2 /* StringConvert.def provides functions to convert numbers to and from strings.
4 Copyright (C) 2001-2023 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
29 #if !defined (_StringConvert_H)
30 # define _StringConvert_H
37 # if !defined (PROC_D)
39 typedef void (*PROC_t
) (void);
40 typedef struct { PROC_t proc
; } PROC
;
43 # include "GDynamicStrings.h"
45 # if defined (_StringConvert_C)
48 # define EXTERN extern
53 IntegerToString - converts INTEGER, i, into a String. The field with
54 can be specified if non zero. Leading characters
55 are defined by padding and this function will
56 prepend a + if sign is set to TRUE.
57 The base allows the caller to generate binary,
58 octal, decimal, hexidecimal numbers.
59 The value of lower is only used when hexidecimal
60 numbers are generated and if TRUE then digits
61 abcdef are used, and if FALSE then ABCDEF are used.
64 EXTERN DynamicStrings_String
StringConvert_IntegerToString (int i
, unsigned int width
, char padding
, unsigned int sign
, unsigned int base
, unsigned int lower
);
67 CardinalToString - converts CARDINAL, c, into a String. The field
68 width can be specified if non zero. Leading
69 characters are defined by padding.
70 The base allows the caller to generate binary,
71 octal, decimal, hexidecimal numbers.
72 The value of lower is only used when hexidecimal
73 numbers are generated and if TRUE then digits
74 abcdef are used, and if FALSE then ABCDEF are used.
77 EXTERN DynamicStrings_String
StringConvert_CardinalToString (unsigned int c
, unsigned int width
, char padding
, unsigned int base
, unsigned int lower
);
80 StringToInteger - converts a string, s, of, base, into an INTEGER.
81 Leading white space is ignored. It stops converting
82 when either the string is exhausted or if an illegal
84 The parameter found is set TRUE if a number was found.
87 EXTERN
int StringConvert_StringToInteger (DynamicStrings_String s
, unsigned int base
, unsigned int *found
);
90 StringToCardinal - converts a string, s, of, base, into a CARDINAL.
91 Leading white space is ignored. It stops converting
92 when either the string is exhausted or if an illegal
94 The parameter found is set TRUE if a number was found.
97 EXTERN
unsigned int StringConvert_StringToCardinal (DynamicStrings_String s
, unsigned int base
, unsigned int *found
);
100 LongIntegerToString - converts LONGINT, i, into a String. The field with
101 can be specified if non zero. Leading characters
102 are defined by padding and this function will
103 prepend a + if sign is set to TRUE.
104 The base allows the caller to generate binary,
105 octal, decimal, hexidecimal numbers.
106 The value of lower is only used when hexidecimal
107 numbers are generated and if TRUE then digits
108 abcdef are used, and if FALSE then ABCDEF are used.
111 EXTERN DynamicStrings_String
StringConvert_LongIntegerToString (long int i
, unsigned int width
, char padding
, unsigned int sign
, unsigned int base
, unsigned int lower
);
114 StringToLongInteger - converts a string, s, of, base, into an LONGINT.
115 Leading white space is ignored. It stops converting
116 when either the string is exhausted or if an illegal
118 The parameter found is set TRUE if a number was found.
121 EXTERN
long int StringConvert_StringToLongInteger (DynamicStrings_String s
, unsigned int base
, unsigned int *found
);
124 LongCardinalToString - converts LONGCARD, c, into a String. The field
125 width can be specified if non zero. Leading
126 characters are defined by padding.
127 The base allows the caller to generate binary,
128 octal, decimal, hexidecimal numbers.
129 The value of lower is only used when hexidecimal
130 numbers are generated and if TRUE then digits
131 abcdef are used, and if FALSE then ABCDEF are used.
134 EXTERN DynamicStrings_String
StringConvert_LongCardinalToString (long unsigned int c
, unsigned int width
, char padding
, unsigned int base
, unsigned int lower
);
137 StringToLongCardinal - converts a string, s, of, base, into a LONGCARD.
138 Leading white space is ignored. It stops converting
139 when either the string is exhausted or if an illegal
141 The parameter found is set TRUE if a number was found.
144 EXTERN
long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s
, unsigned int base
, unsigned int *found
);
147 ShortCardinalToString - converts SHORTCARD, c, into a String. The field
148 width can be specified if non zero. Leading
149 characters are defined by padding.
150 The base allows the caller to generate binary,
151 octal, decimal, hexidecimal numbers.
152 The value of lower is only used when hexidecimal
153 numbers are generated and if TRUE then digits
154 abcdef are used, and if FALSE then ABCDEF are used.
157 EXTERN DynamicStrings_String
StringConvert_ShortCardinalToString (short unsigned int c
, unsigned int width
, char padding
, unsigned int base
, unsigned int lower
);
160 StringToShortCardinal - converts a string, s, of, base, into a SHORTCARD.
161 Leading white space is ignored. It stops converting
162 when either the string is exhausted or if an illegal
164 The parameter found is set TRUE if a number was found.
167 EXTERN
short unsigned int StringConvert_StringToShortCardinal (DynamicStrings_String s
, unsigned int base
, unsigned int *found
);
170 stoi - decimal string to INTEGER
173 EXTERN
int StringConvert_stoi (DynamicStrings_String s
);
176 itos - integer to decimal string.
179 EXTERN DynamicStrings_String
StringConvert_itos (int i
, unsigned int width
, char padding
, unsigned int sign
);
182 ctos - cardinal to decimal string.
185 EXTERN DynamicStrings_String
StringConvert_ctos (unsigned int c
, unsigned int width
, char padding
);
188 stoc - decimal string to CARDINAL
191 EXTERN
unsigned int StringConvert_stoc (DynamicStrings_String s
);
194 hstoi - hexidecimal string to INTEGER
197 EXTERN
int StringConvert_hstoi (DynamicStrings_String s
);
200 ostoi - octal string to INTEGER
203 EXTERN
int StringConvert_ostoi (DynamicStrings_String s
);
206 bstoi - binary string to INTEGER
209 EXTERN
int StringConvert_bstoi (DynamicStrings_String s
);
212 hstoc - hexidecimal string to CARDINAL
215 EXTERN
unsigned int StringConvert_hstoc (DynamicStrings_String s
);
218 ostoc - octal string to CARDINAL
221 EXTERN
unsigned int StringConvert_ostoc (DynamicStrings_String s
);
224 bstoc - binary string to CARDINAL
227 EXTERN
unsigned int StringConvert_bstoc (DynamicStrings_String s
);
230 StringToLongreal - returns a LONGREAL and sets found to TRUE
231 if a legal number is seen.
234 EXTERN
long double StringConvert_StringToLongreal (DynamicStrings_String s
, unsigned int *found
);
237 LongrealToString - converts a LONGREAL number, Real, which has,
238 TotalWidth, and FractionWidth into a string.
242 LongrealToString(1.0, 4, 2) -> '1.00'
243 LongrealToString(12.3, 5, 2) -> '12.30'
244 LongrealToString(12.3, 6, 2) -> ' 12.30'
245 LongrealToString(12.3, 6, 3) -> '12.300'
247 if total width is too small then the fraction
250 LongrealToString(12.3, 5, 3) -> '12.30'
252 If TotalWidth is 0 then the function
253 will return the value of x which is converted
254 into as a fixed point number with exhaustive
258 EXTERN DynamicStrings_String
StringConvert_LongrealToString (long double x
, unsigned int TotalWidth
, unsigned int FractionWidth
);
261 stor - returns a REAL given a string.
264 EXTERN
double StringConvert_stor (DynamicStrings_String s
);
267 stolr - returns a LONGREAL given a string.
270 EXTERN
long double StringConvert_stolr (DynamicStrings_String s
);
273 ToSigFig - returns a floating point or base 10 integer
274 string which is accurate to, n, significant
275 figures. It will return a new String
276 and, s, will be destroyed.
281 rounded to the following significant figures yields
290 EXTERN DynamicStrings_String
StringConvert_ToSigFig (DynamicStrings_String s
, unsigned int n
);
293 ToDecimalPlaces - returns a floating point or base 10 integer
294 string which is accurate to, n, decimal
295 places. It will return a new String
296 and, s, will be destroyed.
297 Decimal places yields, n, digits after
302 rounded to the following decimal places yields
311 EXTERN DynamicStrings_String
StringConvert_ToDecimalPlaces (DynamicStrings_String s
, unsigned int n
);