1 /* do not edit automatically generated by mc from DynamicStrings. */
2 /* DynamicStrings.def provides a dynamic string type and procedures.
4 Copyright (C) 2001-2021 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
37 # if !defined (PROC_D)
39 typedef void (*PROC_t
) (void);
40 typedef struct { PROC_t proc
; } PROC
;
45 # if defined (_DynamicStrings_C)
48 # define EXTERN extern
51 #if !defined (DynamicStrings_String_D)
52 # define DynamicStrings_String_D
53 typedef void *DynamicStrings_String
;
58 InitString - creates and returns a String type object.
59 Initial contents are, a.
62 EXTERN DynamicStrings_String
DynamicStrings_InitString (const char *a_
, unsigned int _a_high
);
65 KillString - frees String, s, and its contents.
69 EXTERN DynamicStrings_String
DynamicStrings_KillString (DynamicStrings_String s
);
72 Fin - finishes with a string, it calls KillString with, s.
73 The purpose of the procedure is to provide a short cut
74 to calling KillString and then testing the return result.
77 EXTERN
void DynamicStrings_Fin (DynamicStrings_String s
);
80 InitStringCharStar - initializes and returns a String to contain
84 EXTERN DynamicStrings_String
DynamicStrings_InitStringCharStar (void * a
);
87 InitStringChar - initializes and returns a String to contain the
91 EXTERN DynamicStrings_String
DynamicStrings_InitStringChar (char ch
);
94 Mark - marks String, s, ready for garbage collection.
97 EXTERN DynamicStrings_String
DynamicStrings_Mark (DynamicStrings_String s
);
100 Length - returns the length of the String, s.
103 EXTERN
unsigned int DynamicStrings_Length (DynamicStrings_String s
);
106 ConCat - returns String, a, after the contents of, b,
110 EXTERN DynamicStrings_String
DynamicStrings_ConCat (DynamicStrings_String a
, DynamicStrings_String b
);
113 ConCatChar - returns String, a, after character, ch,
117 EXTERN DynamicStrings_String
DynamicStrings_ConCatChar (DynamicStrings_String a
, char ch
);
120 Assign - assigns the contents of, b, into, a.
121 String, a, is returned.
124 EXTERN DynamicStrings_String
DynamicStrings_Assign (DynamicStrings_String a
, DynamicStrings_String b
);
127 Dup - duplicate a String, s, returning the copy of s.
130 EXTERN DynamicStrings_String
DynamicStrings_Dup (DynamicStrings_String s
);
133 Add - returns a new String which contains the contents of a and b.
136 EXTERN DynamicStrings_String
DynamicStrings_Add (DynamicStrings_String a
, DynamicStrings_String b
);
139 Equal - returns TRUE if String, a, and, b, are equal.
142 EXTERN
unsigned int DynamicStrings_Equal (DynamicStrings_String a
, DynamicStrings_String b
);
145 EqualCharStar - returns TRUE if contents of String, s, is
146 the same as the string, a.
149 EXTERN
unsigned int DynamicStrings_EqualCharStar (DynamicStrings_String s
, void * a
);
152 EqualArray - returns TRUE if contents of String, s, is the
153 same as the string, a.
156 EXTERN
unsigned int DynamicStrings_EqualArray (DynamicStrings_String s
, const char *a_
, unsigned int _a_high
);
159 Mult - returns a new string which is n concatenations of String, s.
160 If n<=0 then an empty string is returned.
163 EXTERN DynamicStrings_String
DynamicStrings_Mult (DynamicStrings_String s
, unsigned int n
);
166 Slice - returns a new string which contains the elements
169 strings start at element 0
170 Slice(s, 0, 2) will return elements 0, 1 but not 2
171 Slice(s, 1, 3) will return elements 1, 2 but not 3
172 Slice(s, 2, 0) will return elements 2..max
173 Slice(s, 3, -1) will return elements 3..max-1
174 Slice(s, 4, -2) will return elements 4..max-2
177 EXTERN DynamicStrings_String
DynamicStrings_Slice (DynamicStrings_String s
, int low
, int high
);
180 Index - returns the indice of the first occurance of, ch, in
181 String, s. -1 is returned if, ch, does not exist.
182 The search starts at position, o.
185 EXTERN
int DynamicStrings_Index (DynamicStrings_String s
, char ch
, unsigned int o
);
188 RIndex - returns the indice of the last occurance of, ch,
189 in String, s. The search starts at position, o.
190 -1 is returned if, ch, is not found.
193 EXTERN
int DynamicStrings_RIndex (DynamicStrings_String s
, char ch
, unsigned int o
);
196 RemoveComment - assuming that, comment, is a comment delimiter
197 which indicates anything to its right is a comment
198 then strip off the comment and also any white space
199 on the remaining right hand side.
200 It leaves any white space on the left hand side
204 EXTERN DynamicStrings_String
DynamicStrings_RemoveComment (DynamicStrings_String s
, char comment
);
207 RemoveWhitePrefix - removes any leading white space from String, s.
208 A new string is returned.
211 EXTERN DynamicStrings_String
DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s
);
214 RemoveWhitePostfix - removes any leading white space from String, s.
215 A new string is returned.
218 EXTERN DynamicStrings_String
DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s
);
221 ToUpper - returns string, s, after it has had its lower case
222 characters replaced by upper case characters.
223 The string, s, is not duplicated.
226 EXTERN DynamicStrings_String
DynamicStrings_ToUpper (DynamicStrings_String s
);
229 ToLower - returns string, s, after it has had its upper case
230 characters replaced by lower case characters.
231 The string, s, is not duplicated.
234 EXTERN DynamicStrings_String
DynamicStrings_ToLower (DynamicStrings_String s
);
237 CopyOut - copies string, s, to a.
240 EXTERN
void DynamicStrings_CopyOut (char *a
, unsigned int _a_high
, DynamicStrings_String s
);
243 char - returns the character, ch, at position, i, in String, s.
244 As Slice the index can be negative so:
246 char(s, 0) will return the first character
247 char(s, 1) will return the second character
248 char(s, -1) will return the last character
249 char(s, -2) will return the penultimate character
251 a nul character is returned if the index is out of range.
254 EXTERN
char DynamicStrings_char (DynamicStrings_String s
, int i
);
257 string - returns the C style char * of String, s.
260 EXTERN
void * DynamicStrings_string (DynamicStrings_String s
);
263 InitStringDB - the debug version of InitString.
266 EXTERN DynamicStrings_String
DynamicStrings_InitStringDB (const char *a_
, unsigned int _a_high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
269 InitStringCharStarDB - the debug version of InitStringCharStar.
272 EXTERN DynamicStrings_String
DynamicStrings_InitStringCharStarDB (void * a
, const char *file_
, unsigned int _file_high
, unsigned int line
);
275 InitStringCharDB - the debug version of InitStringChar.
278 EXTERN DynamicStrings_String
DynamicStrings_InitStringCharDB (char ch
, const char *file_
, unsigned int _file_high
, unsigned int line
);
281 MultDB - the debug version of MultDB.
284 EXTERN DynamicStrings_String
DynamicStrings_MultDB (DynamicStrings_String s
, unsigned int n
, const char *file_
, unsigned int _file_high
, unsigned int line
);
287 DupDB - the debug version of Dup.
290 EXTERN DynamicStrings_String
DynamicStrings_DupDB (DynamicStrings_String s
, const char *file_
, unsigned int _file_high
, unsigned int line
);
293 SliceDB - debug version of Slice.
296 EXTERN DynamicStrings_String
DynamicStrings_SliceDB (DynamicStrings_String s
, int low
, int high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
299 PushAllocation - pushes the current allocation/deallocation lists.
302 EXTERN
void DynamicStrings_PushAllocation (void);
305 PopAllocation - test to see that all strings are deallocated since
306 the last push. Then it pops to the previous
307 allocation/deallocation lists.
309 If halt is true then the application terminates
310 with an exit code of 1.
313 EXTERN
void DynamicStrings_PopAllocation (unsigned int halt
);
316 PopAllocationExemption - test to see that all strings are
317 deallocated, except string, e, since
319 Then it pops to the previous
320 allocation/deallocation lists.
322 If halt is true then the application
323 terminates with an exit code of 1.
325 The string, e, is returned unmodified,
328 EXTERN DynamicStrings_String
DynamicStrings_PopAllocationExemption (unsigned int halt
, DynamicStrings_String e
);