1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT RUN-TIME COMPONENTS                         --
4--                                                                          --
5--             A D A . S T R I N G S . S U P E R B O U N D E D              --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 2003 Free Software Foundation, Inc.               --
10--                                                                          --
11-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12-- terms of the  GNU General Public License as published  by the Free Soft- --
13-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17-- for  more details.  You should have  received  a copy of the GNU General --
18-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20-- MA 02111-1307, USA.                                                      --
21--                                                                          --
22-- As a special exception,  if other files  instantiate  generics from this --
23-- unit, or you link  this unit with other files  to produce an executable, --
24-- this  unit  does not  by itself cause  the resulting  executable  to  be --
25-- covered  by the  GNU  General  Public  License.  This exception does not --
26-- however invalidate  any other reasons why  the executable file  might be --
27-- covered by the  GNU Public License.                                      --
28--                                                                          --
29-- GNAT was originally developed  by the GNAT team at  New York University. --
30-- Extensive contributions were provided by Ada Core Technologies Inc.      --
31--                                                                          --
32------------------------------------------------------------------------------
33
34--  This non generic package contains most of the implementation of the
35--  generic package Ada.Strings.Bounded.Generic_Bounded_Length.
36
37--  It defines type Super_String as a discriminated record with the maximum
38--  length as the discriminant. Individual instantiations of Strings.Bounded
39--  use this type with an appropriate discriminant value set.
40
41with Ada.Strings.Maps;
42
43package Ada.Strings.Superbounded is
44pragma Preelaborate (Superbounded);
45
46   type Super_String (Max_Length : Positive) is record
47      Current_Length : Natural := 0;
48      Data           : String (1 .. Max_Length) := (others => ASCII.NUL);
49   end record;
50   --  Type Bounded_String in Ada.Strings.Bounded.Generic_Bounded_Length is
51   --  derived from this type, with the constraint of the maximum length.
52
53   --  The subprograms defined for Super_String are similar to those
54   --  defined for Bounded_String, except that they have different names, so
55   --  that they can be renamed in Ada.Strings.Bounded.Generic_Bounded_Length.
56
57   function Super_Length (Source : Super_String) return Natural;
58
59   --------------------------------------------------------
60   -- Conversion, Concatenation, and Selection Functions --
61   --------------------------------------------------------
62
63   function To_Super_String
64     (Source     : String;
65      Max_Length : Natural;
66      Drop       : Truncation := Error)
67      return       Super_String;
68   --  Note the additional parameter Max_Length, which specifies the maximum
69   --  length setting of the resulting Super_String value.
70
71   --  The following procedures have declarations (and semantics) that are
72   --  exactly analogous to those declared in Ada.Strings.Bounded.
73
74   function Super_To_String (Source : Super_String) return String;
75
76   function Super_Append
77     (Left, Right : Super_String;
78      Drop        : Truncation  := Error)
79      return        Super_String;
80
81   function Super_Append
82     (Left  : Super_String;
83      Right : String;
84      Drop  : Truncation := Error)
85      return  Super_String;
86
87   function Super_Append
88     (Left  : String;
89      Right : Super_String;
90      Drop  : Truncation := Error)
91      return  Super_String;
92
93   function Super_Append
94     (Left  : Super_String;
95      Right : Character;
96      Drop  : Truncation := Error)
97      return  Super_String;
98
99   function Super_Append
100     (Left  : Character;
101      Right : Super_String;
102      Drop  : Truncation := Error)
103      return  Super_String;
104
105   procedure Super_Append
106     (Source   : in out Super_String;
107      New_Item : Super_String;
108      Drop     : Truncation  := Error);
109
110   procedure Super_Append
111     (Source   : in out Super_String;
112      New_Item : String;
113      Drop     : Truncation  := Error);
114
115   procedure Super_Append
116     (Source   : in out Super_String;
117      New_Item : Character;
118      Drop     : Truncation  := Error);
119
120   function Concat
121     (Left, Right : Super_String)
122      return        Super_String;
123
124   function Concat
125     (Left  : Super_String;
126      Right : String)
127      return  Super_String;
128
129   function Concat
130     (Left  : String;
131      Right : Super_String)
132      return  Super_String;
133
134   function Concat
135     (Left  : Super_String;
136      Right : Character)
137      return  Super_String;
138
139   function Concat
140     (Left  : Character;
141      Right : Super_String)
142      return  Super_String;
143
144   function Super_Element
145     (Source : Super_String;
146      Index  : Positive)
147      return   Character;
148
149   procedure Super_Replace_Element
150     (Source : in out Super_String;
151      Index  : Positive;
152      By     : Character);
153
154   function Super_Slice
155     (Source : Super_String;
156      Low    : Positive;
157      High   : Natural)
158      return   String;
159
160   function "="  (Left, Right : Super_String) return Boolean;
161
162   function Equal (Left, Right : Super_String) return Boolean renames "=";
163
164   function Equal
165     (Left  : Super_String;
166      Right : String)
167      return  Boolean;
168
169   function Equal
170     (Left  : String;
171      Right : Super_String)
172      return  Boolean;
173
174   function Less (Left, Right : Super_String) return Boolean;
175
176   function Less
177     (Left  : Super_String;
178      Right : String)
179      return  Boolean;
180
181   function Less
182     (Left  : String;
183      Right : Super_String)
184      return  Boolean;
185
186   function Less_Or_Equal (Left, Right : Super_String) return Boolean;
187
188   function Less_Or_Equal
189     (Left  : Super_String;
190      Right : String)
191      return  Boolean;
192
193   function Less_Or_Equal
194     (Left  : String;
195      Right : Super_String)
196      return  Boolean;
197
198   function Greater  (Left, Right : Super_String) return Boolean;
199
200   function Greater
201     (Left  : Super_String;
202      Right : String)
203      return  Boolean;
204
205   function Greater
206     (Left  : String;
207      Right : Super_String)
208      return  Boolean;
209
210   function Greater_Or_Equal (Left, Right : Super_String) return Boolean;
211
212   function Greater_Or_Equal
213     (Left  : Super_String;
214      Right : String)
215      return  Boolean;
216
217   function Greater_Or_Equal
218     (Left  : String;
219      Right : Super_String)
220      return  Boolean;
221
222   ----------------------
223   -- Search Functions --
224   ----------------------
225
226   function Super_Index
227     (Source  : Super_String;
228      Pattern : String;
229      Going   : Direction := Forward;
230      Mapping : Maps.Character_Mapping := Maps.Identity)
231      return    Natural;
232
233   function Super_Index
234     (Source  : Super_String;
235      Pattern : String;
236      Going   : Direction := Forward;
237      Mapping : Maps.Character_Mapping_Function)
238      return    Natural;
239
240   function Super_Index
241     (Source : Super_String;
242      Set    : Maps.Character_Set;
243      Test   : Membership := Inside;
244      Going  : Direction  := Forward)
245      return   Natural;
246
247   function Super_Index_Non_Blank
248     (Source : Super_String;
249      Going  : Direction := Forward)
250      return   Natural;
251
252   function Super_Count
253     (Source  : Super_String;
254      Pattern : String;
255      Mapping : Maps.Character_Mapping := Maps.Identity)
256      return    Natural;
257
258   function Super_Count
259     (Source  : Super_String;
260      Pattern : String;
261      Mapping : Maps.Character_Mapping_Function)
262      return    Natural;
263
264   function Super_Count
265     (Source : Super_String;
266      Set    : Maps.Character_Set)
267      return   Natural;
268
269   procedure Super_Find_Token
270     (Source : Super_String;
271      Set    : Maps.Character_Set;
272      Test   : Membership;
273      First  : out Positive;
274      Last   : out Natural);
275
276   ------------------------------------
277   -- String Translation Subprograms --
278   ------------------------------------
279
280   function Super_Translate
281     (Source   : Super_String;
282      Mapping  : Maps.Character_Mapping)
283      return     Super_String;
284
285   procedure Super_Translate
286     (Source   : in out Super_String;
287      Mapping  : Maps.Character_Mapping);
288
289   function Super_Translate
290     (Source  : Super_String;
291      Mapping : Maps.Character_Mapping_Function)
292      return    Super_String;
293
294   procedure Super_Translate
295     (Source  : in out Super_String;
296      Mapping : Maps.Character_Mapping_Function);
297
298   ---------------------------------------
299   -- String Transformation Subprograms --
300   ---------------------------------------
301
302   function Super_Replace_Slice
303     (Source   : Super_String;
304      Low      : Positive;
305      High     : Natural;
306      By       : String;
307      Drop     : Truncation := Error)
308      return     Super_String;
309
310   procedure Super_Replace_Slice
311     (Source   : in out Super_String;
312      Low      : Positive;
313      High     : Natural;
314      By       : String;
315      Drop     : Truncation := Error);
316
317   function Super_Insert
318     (Source   : Super_String;
319      Before   : Positive;
320      New_Item : String;
321      Drop     : Truncation := Error)
322      return     Super_String;
323
324   procedure Super_Insert
325     (Source   : in out Super_String;
326      Before   : Positive;
327      New_Item : String;
328      Drop     : Truncation := Error);
329
330   function Super_Overwrite
331     (Source    : Super_String;
332      Position  : Positive;
333      New_Item  : String;
334      Drop      : Truncation := Error)
335      return      Super_String;
336
337   procedure Super_Overwrite
338     (Source    : in out Super_String;
339      Position  : Positive;
340      New_Item  : String;
341      Drop      : Truncation := Error);
342
343   function Super_Delete
344     (Source  : Super_String;
345      From    : Positive;
346      Through : Natural)
347      return    Super_String;
348
349   procedure Super_Delete
350     (Source  : in out Super_String;
351      From    : Positive;
352      Through : Natural);
353
354   ---------------------------------
355   -- String Selector Subprograms --
356   ---------------------------------
357
358   function Super_Trim
359     (Source : Super_String;
360      Side   : Trim_End)
361      return   Super_String;
362
363   procedure Super_Trim
364     (Source : in out Super_String;
365      Side   : Trim_End);
366
367   function Super_Trim
368     (Source  : Super_String;
369      Left   : Maps.Character_Set;
370      Right  : Maps.Character_Set)
371      return   Super_String;
372
373   procedure Super_Trim
374     (Source : in out Super_String;
375      Left   : Maps.Character_Set;
376      Right  : Maps.Character_Set);
377
378   function Super_Head
379     (Source : Super_String;
380      Count  : Natural;
381      Pad    : Character := Space;
382      Drop   : Truncation := Error)
383      return   Super_String;
384
385   procedure Super_Head
386     (Source : in out Super_String;
387      Count  : Natural;
388      Pad    : Character  := Space;
389      Drop   : Truncation := Error);
390
391   function Super_Tail
392     (Source : Super_String;
393      Count  : Natural;
394      Pad    : Character  := Space;
395      Drop   : Truncation := Error)
396      return Super_String;
397
398   procedure Super_Tail
399     (Source : in out Super_String;
400      Count  : Natural;
401      Pad    : Character  := Space;
402      Drop   : Truncation := Error);
403
404   ------------------------------------
405   -- String Constructor Subprograms --
406   ------------------------------------
407
408   --  Note: in some of the following routines, there is an extra parameter
409   --  Max_Length which specifies the value of the maximum length for the
410   --  resulting Super_String value.
411
412   function Times
413     (Left       : Natural;
414      Right      : Character;
415      Max_Length : Positive)
416      return       Super_String;
417   --  Note the additional parameter Max_Length
418
419   function Times
420     (Left       : Natural;
421      Right      : String;
422      Max_Length : Positive)
423      return       Super_String;
424   --  Note the additional parameter Max_Length
425
426   function Times
427     (Left  : Natural;
428      Right : Super_String)
429      return  Super_String;
430
431   function Super_Replicate
432     (Count      : Natural;
433      Item       : Character;
434      Drop       : Truncation := Error;
435      Max_Length : Positive)
436      return       Super_String;
437   --  Note the additional parameter Max_Length
438
439   function Super_Replicate
440     (Count      : Natural;
441      Item       : String;
442      Drop       : Truncation := Error;
443      Max_Length : Positive)
444      return       Super_String;
445   --  Note the additional parameter Max_Length
446
447   function Super_Replicate
448     (Count : Natural;
449      Item  : Super_String;
450      Drop  : Truncation := Error)
451      return  Super_String;
452
453private
454
455      --  Pragma Inline declarations
456
457      pragma Inline ("=");
458      pragma Inline (Less);
459      pragma Inline (Less_Or_Equal);
460      pragma Inline (Greater);
461      pragma Inline (Greater_Or_Equal);
462      pragma Inline (Concat);
463      pragma Inline (Super_Count);
464      pragma Inline (Super_Element);
465      pragma Inline (Super_Find_Token);
466      pragma Inline (Super_Index);
467      pragma Inline (Super_Index_Non_Blank);
468      pragma Inline (Super_Length);
469      pragma Inline (Super_Replace_Element);
470      pragma Inline (Super_Slice);
471      pragma Inline (Super_To_String);
472
473end Ada.Strings.Superbounded;
474