1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT RUN-TIME COMPONENTS                         --
4--                                                                          --
5--  A D A . S T R I N G S .  W I D E _ W I D E _ S U P E R B O U N D E D    --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 2003-2012, 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 3,  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.                                     --
17--                                                                          --
18-- As a special exception under Section 7 of GPL version 3, you are granted --
19-- additional permissions described in the GCC Runtime Library Exception,   --
20-- version 3.1, as published by the Free Software Foundation.               --
21--                                                                          --
22-- You should have received a copy of the GNU General Public License and    --
23-- a copy of the GCC Runtime Library Exception along with this program;     --
24-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25-- <http://www.gnu.org/licenses/>.                                          --
26--                                                                          --
27-- GNAT was originally developed  by the GNAT team at  New York University. --
28-- Extensive contributions were provided by Ada Core Technologies Inc.      --
29--                                                                          --
30------------------------------------------------------------------------------
31
32--  This non generic package contains most of the implementation of the
33--  generic package Ada.Strings.Wide_Wide_Bounded.Generic_Bounded_Length.
34
35--  It defines type Super_String as a discriminated record with the maximum
36--  length as the discriminant. Individual instantiations of the package
37--  Strings.Wide_Wide_Bounded.Generic_Bounded_Length use this type with
38--  an appropriate discriminant value set.
39
40with Ada.Strings.Wide_Wide_Maps;
41
42package Ada.Strings.Wide_Wide_Superbounded is
43   pragma Preelaborate;
44
45   Wide_Wide_NUL : constant Wide_Wide_Character :=
46                     Wide_Wide_Character'Val (0);
47
48   --  Wide_Wide_Bounded.Generic_Bounded_Length.Wide_Wide_Bounded_String is
49   --  derived from Super_String, with the constraint of the maximum length.
50
51   type Super_String (Max_Length : Positive) is record
52      Current_Length : Natural := 0;
53      Data           : Wide_Wide_String (1 .. Max_Length);
54      --  A previous version had a default initial value for Data, which is
55      --  no longer necessary, because we now special-case this type in the
56      --  compiler, so "=" composes properly for descendants of this type.
57      --  Leaving it out is more efficient.
58   end record;
59
60   --  The subprograms defined for Super_String are similar to those defined
61   --  for Bounded_Wide_Wide_String, except that they have different names, so
62   --  that they can be renamed in Wide_Wide_Bounded.Generic_Bounded_Length.
63
64   function Super_Length (Source : Super_String) return Natural;
65
66   --------------------------------------------------------
67   -- Conversion, Concatenation, and Selection Functions --
68   --------------------------------------------------------
69
70   function To_Super_String
71     (Source     : Wide_Wide_String;
72      Max_Length : Natural;
73      Drop       : Truncation := Error) return Super_String;
74   --  Note the additional parameter Max_Length, which specifies the maximum
75   --  length setting of the resulting Super_String value.
76
77   --  The following procedures have declarations (and semantics) that are
78   --  exactly analogous to those declared in Ada.Strings.Wide_Wide_Bounded.
79
80   function Super_To_String (Source : Super_String) return Wide_Wide_String;
81
82   procedure Set_Super_String
83     (Target : out Super_String;
84      Source : Wide_Wide_String;
85      Drop   : Truncation := Error);
86
87   function Super_Append
88     (Left  : Super_String;
89      Right : Super_String;
90      Drop  : Truncation := Error) return Super_String;
91
92   function Super_Append
93     (Left  : Super_String;
94      Right : Wide_Wide_String;
95      Drop  : Truncation := Error) return Super_String;
96
97   function Super_Append
98     (Left  : Wide_Wide_String;
99      Right : Super_String;
100      Drop  : Truncation := Error) return Super_String;
101
102   function Super_Append
103     (Left  : Super_String;
104      Right : Wide_Wide_Character;
105      Drop  : Truncation := Error) return Super_String;
106
107   function Super_Append
108     (Left  : Wide_Wide_Character;
109      Right : Super_String;
110      Drop  : Truncation := Error) return Super_String;
111
112   procedure Super_Append
113     (Source   : in out Super_String;
114      New_Item : Super_String;
115      Drop     : Truncation := Error);
116
117   procedure Super_Append
118     (Source   : in out Super_String;
119      New_Item : Wide_Wide_String;
120      Drop     : Truncation := Error);
121
122   procedure Super_Append
123     (Source   : in out Super_String;
124      New_Item : Wide_Wide_Character;
125      Drop     : Truncation := Error);
126
127   function Concat
128     (Left  : Super_String;
129      Right : Super_String) return Super_String;
130
131   function Concat
132     (Left  : Super_String;
133      Right : Wide_Wide_String) return Super_String;
134
135   function Concat
136     (Left  : Wide_Wide_String;
137      Right : Super_String) return Super_String;
138
139   function Concat
140     (Left  : Super_String;
141      Right : Wide_Wide_Character) return Super_String;
142
143   function Concat
144     (Left  : Wide_Wide_Character;
145      Right : Super_String) return Super_String;
146
147   function Super_Element
148     (Source : Super_String;
149      Index  : Positive) return Wide_Wide_Character;
150
151   procedure Super_Replace_Element
152     (Source : in out Super_String;
153      Index  : Positive;
154      By     : Wide_Wide_Character);
155
156   function Super_Slice
157     (Source : Super_String;
158      Low    : Positive;
159      High   : Natural) return Wide_Wide_String;
160
161   function Super_Slice
162     (Source : Super_String;
163      Low    : Positive;
164      High   : Natural) return Super_String;
165
166   procedure Super_Slice
167     (Source : Super_String;
168      Target : out Super_String;
169      Low    : Positive;
170      High   : Natural);
171
172   function "="
173     (Left  : Super_String;
174      Right : Super_String) return Boolean;
175
176   function Equal
177     (Left  : Super_String;
178      Right : Super_String) return Boolean renames "=";
179
180   function Equal
181     (Left  : Super_String;
182      Right : Wide_Wide_String) return Boolean;
183
184   function Equal
185     (Left  : Wide_Wide_String;
186      Right : Super_String) return Boolean;
187
188   function Less
189     (Left  : Super_String;
190      Right : Super_String) return Boolean;
191
192   function Less
193     (Left  : Super_String;
194      Right : Wide_Wide_String) return Boolean;
195
196   function Less
197     (Left  : Wide_Wide_String;
198      Right : Super_String) return Boolean;
199
200   function Less_Or_Equal
201     (Left  : Super_String;
202      Right : Super_String) return Boolean;
203
204   function Less_Or_Equal
205     (Left  : Super_String;
206      Right : Wide_Wide_String) return Boolean;
207
208   function Less_Or_Equal
209     (Left  : Wide_Wide_String;
210      Right : Super_String) return Boolean;
211
212   function Greater
213     (Left  : Super_String;
214      Right : Super_String) return Boolean;
215
216   function Greater
217     (Left  : Super_String;
218      Right : Wide_Wide_String) return Boolean;
219
220   function Greater
221     (Left  : Wide_Wide_String;
222      Right : Super_String) return Boolean;
223
224   function Greater_Or_Equal
225     (Left  : Super_String;
226      Right : Super_String) return Boolean;
227
228   function Greater_Or_Equal
229     (Left  : Super_String;
230      Right : Wide_Wide_String) return Boolean;
231
232   function Greater_Or_Equal
233     (Left  : Wide_Wide_String;
234      Right : Super_String) return Boolean;
235
236   ----------------------
237   -- Search Functions --
238   ----------------------
239
240   function Super_Index
241     (Source  : Super_String;
242      Pattern : Wide_Wide_String;
243      Going   : Direction := Forward;
244      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
245                  Wide_Wide_Maps.Identity)
246      return Natural;
247
248   function Super_Index
249     (Source  : Super_String;
250      Pattern : Wide_Wide_String;
251      Going   : Direction := Forward;
252      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
253      return Natural;
254
255   function Super_Index
256     (Source : Super_String;
257      Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
258      Test   : Membership := Inside;
259      Going  : Direction  := Forward) return Natural;
260
261   function Super_Index
262     (Source  : Super_String;
263      Pattern : Wide_Wide_String;
264      From    : Positive;
265      Going   : Direction := Forward;
266      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
267                  Wide_Wide_Maps.Identity)
268      return Natural;
269
270   function Super_Index
271     (Source  : Super_String;
272      Pattern : Wide_Wide_String;
273      From    : Positive;
274      Going   : Direction := Forward;
275      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
276      return Natural;
277
278   function Super_Index
279     (Source : Super_String;
280      Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
281      From   : Positive;
282      Test   : Membership := Inside;
283      Going  : Direction := Forward) return Natural;
284
285   function Super_Index_Non_Blank
286     (Source : Super_String;
287      Going  : Direction := Forward) return Natural;
288
289   function Super_Index_Non_Blank
290     (Source : Super_String;
291      From   : Positive;
292      Going  : Direction := Forward) return Natural;
293
294   function Super_Count
295     (Source  : Super_String;
296      Pattern : Wide_Wide_String;
297      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
298                  Wide_Wide_Maps.Identity)
299      return Natural;
300
301   function Super_Count
302     (Source  : Super_String;
303      Pattern : Wide_Wide_String;
304      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
305      return Natural;
306
307   function Super_Count
308     (Source : Super_String;
309      Set    : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural;
310
311   procedure Super_Find_Token
312     (Source : Super_String;
313      Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
314      From   : Positive;
315      Test   : Membership;
316      First  : out Positive;
317      Last   : out Natural);
318
319   procedure Super_Find_Token
320     (Source : Super_String;
321      Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
322      Test   : Membership;
323      First  : out Positive;
324      Last   : out Natural);
325
326   ------------------------------------
327   -- String Translation Subprograms --
328   ------------------------------------
329
330   function Super_Translate
331     (Source  : Super_String;
332      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
333      return Super_String;
334
335   procedure Super_Translate
336     (Source   : in out Super_String;
337      Mapping  : Wide_Wide_Maps.Wide_Wide_Character_Mapping);
338
339   function Super_Translate
340     (Source  : Super_String;
341      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
342      return Super_String;
343
344   procedure Super_Translate
345     (Source  : in out Super_String;
346      Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function);
347
348   ---------------------------------------
349   -- String Transformation Subprograms --
350   ---------------------------------------
351
352   function Super_Replace_Slice
353     (Source : Super_String;
354      Low    : Positive;
355      High   : Natural;
356      By     : Wide_Wide_String;
357      Drop   : Truncation := Error) return Super_String;
358
359   procedure Super_Replace_Slice
360     (Source  : in out Super_String;
361      Low     : Positive;
362      High    : Natural;
363      By      : Wide_Wide_String;
364      Drop    : Truncation := Error);
365
366   function Super_Insert
367     (Source   : Super_String;
368      Before   : Positive;
369      New_Item : Wide_Wide_String;
370      Drop     : Truncation := Error) return Super_String;
371
372   procedure Super_Insert
373     (Source   : in out Super_String;
374      Before   : Positive;
375      New_Item : Wide_Wide_String;
376      Drop     : Truncation := Error);
377
378   function Super_Overwrite
379     (Source   : Super_String;
380      Position : Positive;
381      New_Item : Wide_Wide_String;
382      Drop     : Truncation := Error) return Super_String;
383
384   procedure Super_Overwrite
385     (Source    : in out Super_String;
386      Position  : Positive;
387      New_Item  : Wide_Wide_String;
388      Drop      : Truncation := Error);
389
390   function Super_Delete
391     (Source  : Super_String;
392      From    : Positive;
393      Through : Natural) return Super_String;
394
395   procedure Super_Delete
396     (Source  : in out Super_String;
397      From    : Positive;
398      Through : Natural);
399
400   ---------------------------------
401   -- String Selector Subprograms --
402   ---------------------------------
403
404   function Super_Trim
405     (Source : Super_String;
406      Side   : Trim_End) return Super_String;
407
408   procedure Super_Trim
409     (Source : in out Super_String;
410      Side   : Trim_End);
411
412   function Super_Trim
413     (Source : Super_String;
414      Left   : Wide_Wide_Maps.Wide_Wide_Character_Set;
415      Right  : Wide_Wide_Maps.Wide_Wide_Character_Set) return Super_String;
416
417   procedure Super_Trim
418     (Source : in out Super_String;
419      Left   : Wide_Wide_Maps.Wide_Wide_Character_Set;
420      Right  : Wide_Wide_Maps.Wide_Wide_Character_Set);
421
422   function Super_Head
423     (Source : Super_String;
424      Count  : Natural;
425      Pad    : Wide_Wide_Character := Wide_Wide_Space;
426      Drop   : Truncation := Error) return Super_String;
427
428   procedure Super_Head
429     (Source : in out Super_String;
430      Count  : Natural;
431      Pad    : Wide_Wide_Character := Wide_Wide_Space;
432      Drop   : Truncation := Error);
433
434   function Super_Tail
435     (Source : Super_String;
436      Count  : Natural;
437      Pad    : Wide_Wide_Character := Wide_Wide_Space;
438      Drop   : Truncation := Error) return Super_String;
439
440   procedure Super_Tail
441     (Source : in out Super_String;
442      Count  : Natural;
443      Pad    : Wide_Wide_Character := Wide_Wide_Space;
444      Drop   : Truncation := Error);
445
446   ------------------------------------
447   -- String Constructor Subprograms --
448   ------------------------------------
449
450   --  Note: in some of the following routines, there is an extra parameter
451   --  Max_Length which specifies the value of the maximum length for the
452   --  resulting Super_String value.
453
454   function Times
455     (Left       : Natural;
456      Right      : Wide_Wide_Character;
457      Max_Length : Positive) return Super_String;
458   --  Note the additional parameter Max_Length
459
460   function Times
461     (Left       : Natural;
462      Right      : Wide_Wide_String;
463      Max_Length : Positive) return Super_String;
464   --  Note the additional parameter Max_Length
465
466   function Times
467     (Left  : Natural;
468      Right : Super_String) return Super_String;
469
470   function Super_Replicate
471     (Count      : Natural;
472      Item       : Wide_Wide_Character;
473      Drop       : Truncation := Error;
474      Max_Length : Positive) return Super_String;
475   --  Note the additional parameter Max_Length
476
477   function Super_Replicate
478     (Count      : Natural;
479      Item       : Wide_Wide_String;
480      Drop       : Truncation := Error;
481      Max_Length : Positive) return Super_String;
482   --  Note the additional parameter Max_Length
483
484   function Super_Replicate
485     (Count : Natural;
486      Item  : Super_String;
487      Drop  : Truncation := Error) return Super_String;
488
489private
490      --  Pragma Inline declarations
491
492      pragma Inline ("=");
493      pragma Inline (Less);
494      pragma Inline (Less_Or_Equal);
495      pragma Inline (Greater);
496      pragma Inline (Greater_Or_Equal);
497      pragma Inline (Concat);
498      pragma Inline (Super_Count);
499      pragma Inline (Super_Element);
500      pragma Inline (Super_Find_Token);
501      pragma Inline (Super_Index);
502      pragma Inline (Super_Index_Non_Blank);
503      pragma Inline (Super_Length);
504      pragma Inline (Super_Replace_Element);
505      pragma Inline (Super_Slice);
506      pragma Inline (Super_To_String);
507
508end Ada.Strings.Wide_Wide_Superbounded;
509