-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathString.def
61 lines (34 loc) · 1.74 KB
/
String.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(*!m2r10*) (* Copyright (c) 2015 B.Kowarsch. All rights reserved. *)
DEFINITION MODULE String;
(* Variable Length String Library *)
IMPORT Hash;
TYPE String = OPAQUE;
(* The payload of a string is stored with its meta-data: length, hash value and
reference count. Upon initialisation, the reference count is set to one. *)
(* Constructors *)
PROCEDURE New ( VAR s : String; CONST initWith : ARRAY OF CHAR );
(* Passes back a newly allocated string in s, initialised with the contents of
initWith. Passes back NIL if unsuccessful. *)
PROCEDURE NewWithSlice
( VAR s : String; CONST copyFrom : ARRAY OF CHAR; start, end : CARDINAL );
(* Passes back a newly allocated string in s, initialised with the contents of
slice copyFrom[start .. end]. Passes back NIL if unsuccessful. *)
(* Memory Management *)
PROCEDURE Retain ( s : String );
(* Increments the reference count of s. *)
PROCEDURE Release ( VAR s : String );
(* Decrements the reference count of s, deallocates if the result is zero.
Passes back NIL in s if s has been deallocated. *)
(* Operations *)
PROCEDURE length ( s : String ) : CARDINAL;
(* Returns the length of s. Returns zero if s is NIL. *)
PROCEDURE hash ( s : String ) : Hash;
(* Returns the hash value of s. Returns zero if s is NIL. *)
PROCEDURE toAOC ( s : String; VAR aoc : ARRAY OF CHAR );
(* Passes back the contents of s as an ASCII.NUL terminated character array
in aoc. Passes back ASCII.NUL if the operation is unsuccessful. *)
PROCEDURE matches ( s1, s2 : String ) : BOOLEAN;
(* Returns TRUE if the contents of s1 and s2 match, otherwise FALSE. *)
PROCEDURE matchesAOC ( s : String; aoc : ARRAY OF CHAR ) : BOOLEAN;
(* Returns TRUE if the contents of s match those of aoc, otherwise FALSE. *)
END String.