]> gcc.gnu.org Git - gcc.git/blame - gcc/m2/gm2-libs-log/Strings.mod
Modula-2 rename logitech libraries to log
[gcc.git] / gcc / m2 / gm2-libs-log / Strings.mod
CommitLineData
1eee94d3
GM
1(* Strings.mod provides a Logitech-3.0 compatible library.
2
83ffe9cd 3Copyright (C) 2005-2023 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. *)
26
27IMPLEMENTATION MODULE Strings ;
28
29FROM ASCII IMPORT nul ;
30IMPORT StrLib ;
31IMPORT DynamicStrings ;
32
33
34(*
35 Assign - source := dest.
36*)
37
38PROCEDURE Assign (VAR dest: ARRAY OF CHAR; source: ARRAY OF CHAR) ;
39BEGIN
40 StrLib.StrCopy(source, dest)
41END Assign ;
42
43
44(*
45 Insert - insert the string, substr, into str at position, index.
46 substr, is added to the end of, str, if, index >= length(str)
47*)
48
49PROCEDURE Insert (substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR;
50 index: CARDINAL) ;
51VAR
52 s1, s2: DynamicStrings.String ;
53BEGIN
54 IF index>Length(str)
55 THEN
56 ConCat(str, substr, str)
57 ELSE
58 s1 := DynamicStrings.InitString(str) ;
59 s2 := DynamicStrings.ConCat(DynamicStrings.Slice(s1, 0, index),
60 DynamicStrings.Mark(DynamicStrings.InitString(str))) ;
61 s2 := DynamicStrings.ConCat(s2, DynamicStrings.Slice(s1, index, 0)) ;
62 DynamicStrings.CopyOut(str, s2) ;
63 s1 := DynamicStrings.KillString(s1) ;
64 s2 := DynamicStrings.KillString(s2)
65 END
66END Insert ;
67
68
69(*
70 Delete - delete len characters from, str, starting at, index.
71*)
72
73PROCEDURE Delete (VAR str: ARRAY OF CHAR; index: CARDINAL; length: CARDINAL) ;
74VAR
75 s: DynamicStrings.String ;
76BEGIN
77 s := DynamicStrings.InitString(str) ;
78 s := DynamicStrings.ConCat(DynamicStrings.Mark(DynamicStrings.Slice(s, 0, index)),
79 DynamicStrings.Mark(DynamicStrings.Slice(s, index+length, 0))) ;
80 DynamicStrings.CopyOut(str, s) ;
81 s := DynamicStrings.KillString(s)
82END Delete ;
83
84
85(*
86 Pos - return the first position of, substr, in, str.
87*)
88
89PROCEDURE Pos (substr, str: ARRAY OF CHAR) : CARDINAL ;
90VAR
91 i, k, l : INTEGER ;
92 s1, s2, s3: DynamicStrings.String ;
93BEGIN
94 s1 := DynamicStrings.InitString(str) ;
95 s2 := DynamicStrings.InitString(substr) ;
96 k := DynamicStrings.Length(s1) ;
97 l := DynamicStrings.Length(s2) ;
98 i := 0 ;
99 REPEAT
100 i := DynamicStrings.Index(s1, DynamicStrings.char(s2, 0), i) ;
101 IF i>=0
102 THEN
103 s3 := DynamicStrings.Slice(s1, i, l) ;
104 IF DynamicStrings.Equal(s3, s2)
105 THEN
106 s1 := DynamicStrings.KillString(s1) ;
107 s2 := DynamicStrings.KillString(s2) ;
108 s3 := DynamicStrings.KillString(s3) ;
109 RETURN( i )
110 END ;
111 s3 := DynamicStrings.KillString(s3)
112 END ;
113 INC(i)
114 UNTIL i>=k ;
115 s1 := DynamicStrings.KillString(s1) ;
116 s2 := DynamicStrings.KillString(s2) ;
117 s3 := DynamicStrings.KillString(s3) ;
118 RETURN( HIGH(str)+1 )
119END Pos ;
120
121
122(*
123 Copy - copy at most, length, characters in, substr, to, str,
124 starting at position, index.
125*)
126
127PROCEDURE Copy (str: ARRAY OF CHAR;
128 index, length: CARDINAL; VAR result: ARRAY OF CHAR) ;
129VAR
130 s1, s2: DynamicStrings.String ;
131BEGIN
132 s1 := DynamicStrings.InitString(str) ;
133 s2 := DynamicStrings.Slice(s1, index, index+length) ;
134 DynamicStrings.CopyOut(result, s2) ;
135 s1 := DynamicStrings.KillString(s1) ;
136 s2 := DynamicStrings.KillString(s2)
137END Copy ;
138
139
140(*
141 ConCat - concatenates two strings, s1, and, s2
142 and places the result into, dest.
143*)
144
145PROCEDURE ConCat (s1, s2: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR) ;
146BEGIN
147 StrLib.StrConCat(s1, s2, dest)
148END ConCat ;
149
150
151(*
152 Length - return the length of string, s.
153*)
154
155PROCEDURE Length (s: ARRAY OF CHAR) : CARDINAL ;
156BEGIN
157 RETURN( StrLib.StrLen(s) )
158END Length ;
159
160
161(*
162 CompareStr - compare two strings, left, and, right.
163*)
164
165PROCEDURE CompareStr (left, right: ARRAY OF CHAR) : INTEGER ;
166BEGIN
167 IF StrLib.StrLess(left, right)
168 THEN
169 RETURN( -1 )
170 ELSIF StrLib.StrEqual(left, right)
171 THEN
172 RETURN( 0 )
173 ELSE
174 RETURN( 1 )
175 END
176END CompareStr ;
177
178
179END Strings.
This page took 0.13836 seconds and 5 git commands to generate.