1 /* do not edit automatically generated by mc from DynamicStrings. */
2 /* DynamicStrings.def provides a dynamic string type and procedures.
4 Copyright (C) 2001-2024 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 (_DynamicStrings_H)
30 # define _DynamicStrings_H
38 # if !defined (PROC_D)
40 typedef void (*PROC_t
) (void);
41 typedef struct { PROC_t proc
; } PROC
;
46 # if defined (_DynamicStrings_C)
49 # define EXTERN extern
52 #if !defined (DynamicStrings_String_D)
53 # define DynamicStrings_String_D
54 typedef void *DynamicStrings_String
;
59 InitString - creates and returns a String type object.
60 Initial contents are, a.
63 EXTERN DynamicStrings_String
DynamicStrings_InitString (const char *a_
, unsigned int _a_high
);
66 KillString - frees String, s, and its contents.
70 EXTERN DynamicStrings_String
DynamicStrings_KillString (DynamicStrings_String s
);
73 Fin - finishes with a string, it calls KillString with, s.
74 The purpose of the procedure is to provide a short cut
75 to calling KillString and then testing the return result.
78 EXTERN
void DynamicStrings_Fin (DynamicStrings_String s
);
81 InitStringCharStar - initializes and returns a String to contain
85 EXTERN DynamicStrings_String
DynamicStrings_InitStringCharStar (void * a
);
88 InitStringChar - initializes and returns a String to contain the
92 EXTERN DynamicStrings_String
DynamicStrings_InitStringChar (char ch
);
95 Mark - marks String, s, ready for garbage collection.
98 EXTERN DynamicStrings_String
DynamicStrings_Mark (DynamicStrings_String s
);
101 Length - returns the length of the String, s.
104 EXTERN
unsigned int DynamicStrings_Length (DynamicStrings_String s
);
107 ConCat - returns String, a, after the contents of, b,
111 EXTERN DynamicStrings_String
DynamicStrings_ConCat (DynamicStrings_String a
, DynamicStrings_String b
);
114 ConCatChar - returns String, a, after character, ch,
118 EXTERN DynamicStrings_String
DynamicStrings_ConCatChar (DynamicStrings_String a
, char ch
);
121 Assign - assigns the contents of, b, into, a.
122 String, a, is returned.
125 EXTERN DynamicStrings_String
DynamicStrings_Assign (DynamicStrings_String a
, DynamicStrings_String b
);
128 ReplaceChar - returns string s after it has changed all
129 occurances of from to to.
132 EXTERN DynamicStrings_String
DynamicStrings_ReplaceChar (DynamicStrings_String s
, char from
, char to
);
135 Dup - duplicate a String, s, returning the copy of s.
138 EXTERN DynamicStrings_String
DynamicStrings_Dup (DynamicStrings_String s
);
141 Add - returns a new String which contains the contents of a and b.
144 EXTERN DynamicStrings_String
DynamicStrings_Add (DynamicStrings_String a
, DynamicStrings_String b
);
147 Equal - returns TRUE if String, a, and, b, are equal.
150 EXTERN
bool DynamicStrings_Equal (DynamicStrings_String a
, DynamicStrings_String b
);
153 EqualCharStar - returns TRUE if contents of String, s, is
154 the same as the string, a.
157 EXTERN
bool DynamicStrings_EqualCharStar (DynamicStrings_String s
, void * a
);
160 EqualArray - returns TRUE if contents of String, s, is the
161 same as the string, a.
164 EXTERN
bool DynamicStrings_EqualArray (DynamicStrings_String s
, const char *a_
, unsigned int _a_high
);
167 Mult - returns a new string which is n concatenations of String, s.
168 If n<=0 then an empty string is returned.
171 EXTERN DynamicStrings_String
DynamicStrings_Mult (DynamicStrings_String s
, unsigned int n
);
174 Slice - returns a new string which contains the elements
177 strings start at element 0
178 Slice(s, 0, 2) will return elements 0, 1 but not 2
179 Slice(s, 1, 3) will return elements 1, 2 but not 3
180 Slice(s, 2, 0) will return elements 2..max
181 Slice(s, 3, -1) will return elements 3..max-1
182 Slice(s, 4, -2) will return elements 4..max-2
185 EXTERN DynamicStrings_String
DynamicStrings_Slice (DynamicStrings_String s
, int low
, int high
);
188 Index - returns the indice of the first occurance of, ch, in
189 String, s. -1 is returned if, ch, does not exist.
190 The search starts at position, o.
193 EXTERN
int DynamicStrings_Index (DynamicStrings_String s
, char ch
, unsigned int o
);
196 RIndex - returns the indice of the last occurance of, ch,
197 in String, s. The search starts at position, o.
198 -1 is returned if ch is not found. The search
199 is performed left to right.
202 EXTERN
int DynamicStrings_RIndex (DynamicStrings_String s
, char ch
, unsigned int o
);
205 ReverseIndex - returns the indice of the last occurance of ch
206 in String s. The search starts at position o
207 and searches from right to left. The start position
208 may be indexed negatively from the right (-1 is the
210 The return value if ch is found will always be positive.
211 -1 is returned if ch is not found.
214 EXTERN
int DynamicStrings_ReverseIndex (DynamicStrings_String s
, char ch
, int o
);
217 RemoveComment - assuming that, comment, is a comment delimiter
218 which indicates anything to its right is a comment
219 then strip off the comment and also any white space
220 on the remaining right hand side.
221 It leaves any white space on the left hand side
225 EXTERN DynamicStrings_String
DynamicStrings_RemoveComment (DynamicStrings_String s
, char comment
);
228 RemoveWhitePrefix - removes any leading white space from String, s.
229 A new string is returned.
232 EXTERN DynamicStrings_String
DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s
);
235 RemoveWhitePostfix - removes any leading white space from String, s.
236 A new string is returned.
239 EXTERN DynamicStrings_String
DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s
);
242 ToUpper - returns string, s, after it has had its lower case
243 characters replaced by upper case characters.
244 The string, s, is not duplicated.
247 EXTERN DynamicStrings_String
DynamicStrings_ToUpper (DynamicStrings_String s
);
250 ToLower - returns string, s, after it has had its upper case
251 characters replaced by lower case characters.
252 The string, s, is not duplicated.
255 EXTERN DynamicStrings_String
DynamicStrings_ToLower (DynamicStrings_String s
);
258 CopyOut - copies string, s, to a.
261 EXTERN
void DynamicStrings_CopyOut (char *a
, unsigned int _a_high
, DynamicStrings_String s
);
264 char - returns the character, ch, at position, i, in String, s.
265 As Slice the index can be negative so:
267 char(s, 0) will return the first character
268 char(s, 1) will return the second character
269 char(s, -1) will return the last character
270 char(s, -2) will return the penultimate character
272 a nul character is returned if the index is out of range.
275 EXTERN
char DynamicStrings_char (DynamicStrings_String s
, int i
);
278 string - returns the C style char * of String, s.
281 EXTERN
void * DynamicStrings_string (DynamicStrings_String s
);
284 InitStringDB - the debug version of InitString.
287 EXTERN DynamicStrings_String
DynamicStrings_InitStringDB (const char *a_
, unsigned int _a_high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
290 InitStringCharStarDB - the debug version of InitStringCharStar.
293 EXTERN DynamicStrings_String
DynamicStrings_InitStringCharStarDB (void * a
, const char *file_
, unsigned int _file_high
, unsigned int line
);
296 InitStringCharDB - the debug version of InitStringChar.
299 EXTERN DynamicStrings_String
DynamicStrings_InitStringCharDB (char ch
, const char *file_
, unsigned int _file_high
, unsigned int line
);
302 MultDB - the debug version of MultDB.
305 EXTERN DynamicStrings_String
DynamicStrings_MultDB (DynamicStrings_String s
, unsigned int n
, const char *file_
, unsigned int _file_high
, unsigned int line
);
308 DupDB - the debug version of Dup.
311 EXTERN DynamicStrings_String
DynamicStrings_DupDB (DynamicStrings_String s
, const char *file_
, unsigned int _file_high
, unsigned int line
);
314 SliceDB - debug version of Slice.
317 EXTERN DynamicStrings_String
DynamicStrings_SliceDB (DynamicStrings_String s
, int low
, int high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
320 PushAllocation - pushes the current allocation/deallocation lists.
323 EXTERN
void DynamicStrings_PushAllocation (void);
326 PopAllocation - test to see that all strings are deallocated since
327 the last push. Then it pops to the previous
328 allocation/deallocation lists.
330 If halt is true then the application terminates
331 with an exit code of 1.
334 EXTERN
void DynamicStrings_PopAllocation (bool halt
);
337 PopAllocationExemption - test to see that all strings are
338 deallocated, except string e since
340 Post-condition: it pops to the previous
341 allocation/deallocation lists.
343 If halt is true then the application
344 terminates with an exit code of 1.
346 The string, e, is returned unmodified,
349 EXTERN DynamicStrings_String
DynamicStrings_PopAllocationExemption (bool halt
, DynamicStrings_String e
);