1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . S U P E R B O U N D E D --
9 -- Copyright (C) 2003-2012, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This non generic package contains most of the implementation of the
33 -- generic package Ada.Strings.Bounded.Generic_Bounded_Length.
35 -- It defines type Super_String as a discriminated record with the maximum
36 -- length as the discriminant. Individual instantiations of Strings.Bounded
37 -- use this type with an appropriate discriminant value set.
39 with Ada
.Strings
.Maps
;
41 package Ada
.Strings
.Superbounded
is
44 -- Type Bounded_String in Ada.Strings.Bounded.Generic_Bounded_Length is
45 -- derived from Super_String, with the constraint of the maximum length.
47 type Super_String
(Max_Length
: Positive) is record
48 Current_Length
: Natural := 0;
49 Data
: String (1 .. Max_Length
);
50 -- A previous version had a default initial value for Data, which is
51 -- no longer necessary, because we now special-case this type in the
52 -- compiler, so "=" composes properly for descendants of this type.
53 -- Leaving it out is more efficient.
56 -- The subprograms defined for Super_String are similar to those
57 -- defined for Bounded_String, except that they have different names, so
58 -- that they can be renamed in Ada.Strings.Bounded.Generic_Bounded_Length.
60 function Super_Length
(Source
: Super_String
) return Natural;
62 --------------------------------------------------------
63 -- Conversion, Concatenation, and Selection Functions --
64 --------------------------------------------------------
66 function To_Super_String
69 Drop
: Truncation
:= Error
) return Super_String
;
70 -- Note the additional parameter Max_Length, which specifies the maximum
71 -- length setting of the resulting Super_String value.
73 -- The following procedures have declarations (and semantics) that are
74 -- exactly analogous to those declared in Ada.Strings.Bounded.
76 function Super_To_String
(Source
: Super_String
) return String;
78 procedure Set_Super_String
79 (Target
: out Super_String
;
81 Drop
: Truncation
:= Error
);
86 Drop
: Truncation
:= Error
) return Super_String
;
91 Drop
: Truncation
:= Error
) return Super_String
;
96 Drop
: Truncation
:= Error
) return Super_String
;
101 Drop
: Truncation
:= Error
) return Super_String
;
103 function Super_Append
105 Right
: Super_String
;
106 Drop
: Truncation
:= Error
) return Super_String
;
108 procedure Super_Append
109 (Source
: in out Super_String
;
110 New_Item
: Super_String
;
111 Drop
: Truncation
:= Error
);
113 procedure Super_Append
114 (Source
: in out Super_String
;
116 Drop
: Truncation
:= Error
);
118 procedure Super_Append
119 (Source
: in out Super_String
;
120 New_Item
: Character;
121 Drop
: Truncation
:= Error
);
124 (Left
: Super_String
;
125 Right
: Super_String
) return Super_String
;
128 (Left
: Super_String
;
129 Right
: String) return Super_String
;
133 Right
: Super_String
) return Super_String
;
136 (Left
: Super_String
;
137 Right
: Character) return Super_String
;
141 Right
: Super_String
) return Super_String
;
143 function Super_Element
144 (Source
: Super_String
;
145 Index
: Positive) return Character;
147 procedure Super_Replace_Element
148 (Source
: in out Super_String
;
153 (Source
: Super_String
;
155 High
: Natural) return String;
158 (Source
: Super_String
;
160 High
: Natural) return Super_String
;
162 procedure Super_Slice
163 (Source
: Super_String
;
164 Target
: out Super_String
;
169 (Left
: Super_String
;
170 Right
: Super_String
) return Boolean;
173 (Left
: Super_String
;
174 Right
: Super_String
) return Boolean renames "=";
177 (Left
: Super_String
;
178 Right
: String) return Boolean;
182 Right
: Super_String
) return Boolean;
185 (Left
: Super_String
;
186 Right
: Super_String
) return Boolean;
189 (Left
: Super_String
;
190 Right
: String) return Boolean;
194 Right
: Super_String
) return Boolean;
196 function Less_Or_Equal
197 (Left
: Super_String
;
198 Right
: Super_String
) return Boolean;
200 function Less_Or_Equal
201 (Left
: Super_String
;
202 Right
: String) return Boolean;
204 function Less_Or_Equal
206 Right
: Super_String
) return Boolean;
209 (Left
: Super_String
;
210 Right
: Super_String
) return Boolean;
213 (Left
: Super_String
;
214 Right
: String) return Boolean;
218 Right
: Super_String
) return Boolean;
220 function Greater_Or_Equal
221 (Left
: Super_String
;
222 Right
: Super_String
) return Boolean;
224 function Greater_Or_Equal
225 (Left
: Super_String
;
226 Right
: String) return Boolean;
228 function Greater_Or_Equal
230 Right
: Super_String
) return Boolean;
232 ----------------------
233 -- Search Functions --
234 ----------------------
237 (Source
: Super_String
;
239 Going
: Direction
:= Forward
;
240 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
243 (Source
: Super_String
;
245 Going
: Direction
:= Forward
;
246 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
249 (Source
: Super_String
;
250 Set
: Maps
.Character_Set
;
251 Test
: Membership
:= Inside
;
252 Going
: Direction
:= Forward
) return Natural;
255 (Source
: Super_String
;
258 Going
: Direction
:= Forward
;
259 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
262 (Source
: Super_String
;
265 Going
: Direction
:= Forward
;
266 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
269 (Source
: Super_String
;
270 Set
: Maps
.Character_Set
;
272 Test
: Membership
:= Inside
;
273 Going
: Direction
:= Forward
) return Natural;
275 function Super_Index_Non_Blank
276 (Source
: Super_String
;
277 Going
: Direction
:= Forward
) return Natural;
279 function Super_Index_Non_Blank
280 (Source
: Super_String
;
282 Going
: Direction
:= Forward
) return Natural;
285 (Source
: Super_String
;
287 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
290 (Source
: Super_String
;
292 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
295 (Source
: Super_String
;
296 Set
: Maps
.Character_Set
) return Natural;
298 procedure Super_Find_Token
299 (Source
: Super_String
;
300 Set
: Maps
.Character_Set
;
303 First
: out Positive;
306 procedure Super_Find_Token
307 (Source
: Super_String
;
308 Set
: Maps
.Character_Set
;
310 First
: out Positive;
313 ------------------------------------
314 -- String Translation Subprograms --
315 ------------------------------------
317 function Super_Translate
318 (Source
: Super_String
;
319 Mapping
: Maps
.Character_Mapping
) return Super_String
;
321 procedure Super_Translate
322 (Source
: in out Super_String
;
323 Mapping
: Maps
.Character_Mapping
);
325 function Super_Translate
326 (Source
: Super_String
;
327 Mapping
: Maps
.Character_Mapping_Function
) return Super_String
;
329 procedure Super_Translate
330 (Source
: in out Super_String
;
331 Mapping
: Maps
.Character_Mapping_Function
);
333 ---------------------------------------
334 -- String Transformation Subprograms --
335 ---------------------------------------
337 function Super_Replace_Slice
338 (Source
: Super_String
;
342 Drop
: Truncation
:= Error
) return Super_String
;
344 procedure Super_Replace_Slice
345 (Source
: in out Super_String
;
349 Drop
: Truncation
:= Error
);
351 function Super_Insert
352 (Source
: Super_String
;
355 Drop
: Truncation
:= Error
) return Super_String
;
357 procedure Super_Insert
358 (Source
: in out Super_String
;
361 Drop
: Truncation
:= Error
);
363 function Super_Overwrite
364 (Source
: Super_String
;
367 Drop
: Truncation
:= Error
) return Super_String
;
369 procedure Super_Overwrite
370 (Source
: in out Super_String
;
373 Drop
: Truncation
:= Error
);
375 function Super_Delete
376 (Source
: Super_String
;
378 Through
: Natural) return Super_String
;
380 procedure Super_Delete
381 (Source
: in out Super_String
;
385 ---------------------------------
386 -- String Selector Subprograms --
387 ---------------------------------
390 (Source
: Super_String
;
391 Side
: Trim_End
) return Super_String
;
394 (Source
: in out Super_String
;
398 (Source
: Super_String
;
399 Left
: Maps
.Character_Set
;
400 Right
: Maps
.Character_Set
) return Super_String
;
403 (Source
: in out Super_String
;
404 Left
: Maps
.Character_Set
;
405 Right
: Maps
.Character_Set
);
408 (Source
: Super_String
;
410 Pad
: Character := Space
;
411 Drop
: Truncation
:= Error
) return Super_String
;
414 (Source
: in out Super_String
;
416 Pad
: Character := Space
;
417 Drop
: Truncation
:= Error
);
420 (Source
: Super_String
;
422 Pad
: Character := Space
;
423 Drop
: Truncation
:= Error
) return Super_String
;
426 (Source
: in out Super_String
;
428 Pad
: Character := Space
;
429 Drop
: Truncation
:= Error
);
431 ------------------------------------
432 -- String Constructor Subprograms --
433 ------------------------------------
435 -- Note: in some of the following routines, there is an extra parameter
436 -- Max_Length which specifies the value of the maximum length for the
437 -- resulting Super_String value.
442 Max_Length
: Positive) return Super_String
;
443 -- Note the additional parameter Max_Length
448 Max_Length
: Positive) return Super_String
;
449 -- Note the additional parameter Max_Length
453 Right
: Super_String
) return Super_String
;
455 function Super_Replicate
458 Drop
: Truncation
:= Error
;
459 Max_Length
: Positive) return Super_String
;
460 -- Note the additional parameter Max_Length
462 function Super_Replicate
465 Drop
: Truncation
:= Error
;
466 Max_Length
: Positive) return Super_String
;
467 -- Note the additional parameter Max_Length
469 function Super_Replicate
472 Drop
: Truncation
:= Error
) return Super_String
;
475 -- Pragma Inline declarations
478 pragma Inline
(Less
);
479 pragma Inline
(Less_Or_Equal
);
480 pragma Inline
(Greater
);
481 pragma Inline
(Greater_Or_Equal
);
482 pragma Inline
(Concat
);
483 pragma Inline
(Super_Count
);
484 pragma Inline
(Super_Element
);
485 pragma Inline
(Super_Find_Token
);
486 pragma Inline
(Super_Index
);
487 pragma Inline
(Super_Index_Non_Blank
);
488 pragma Inline
(Super_Length
);
489 pragma Inline
(Super_Replace_Element
);
490 pragma Inline
(Super_Slice
);
491 pragma Inline
(Super_To_String
);
493 end Ada
.Strings
.Superbounded
;