1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ 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.Wide_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 the package
37 -- Strings.Wide_Bounded.Generic_Bounded_Length use this type with
38 -- an appropriate discriminant value set.
40 with Ada
.Strings
.Wide_Maps
;
42 package Ada
.Strings
.Wide_Superbounded
is
45 Wide_NUL
: constant Wide_Character := Wide_Character'Val (0);
47 -- Ada.Strings.Wide_Bounded.Generic_Bounded_Length.Wide_Bounded_String is
48 -- derived from Super_String, with the constraint of the maximum length.
50 type Super_String
(Max_Length
: Positive) is record
51 Current_Length
: Natural := 0;
52 Data
: Wide_String (1 .. Max_Length
);
53 -- A previous version had a default initial value for Data, which is
54 -- no longer necessary, because we now special-case this type in the
55 -- compiler, so "=" composes properly for descendants of this type.
56 -- Leaving it out is more efficient.
59 -- The subprograms defined for Super_String are similar to those defined
60 -- for Bounded_Wide_String, except that they have different names, so that
61 -- they can be renamed in Ada.Strings.Wide_Bounded.Generic_Bounded_Length.
63 function Super_Length
(Source
: Super_String
) return Natural;
65 --------------------------------------------------------
66 -- Conversion, Concatenation, and Selection Functions --
67 --------------------------------------------------------
69 function To_Super_String
70 (Source
: Wide_String;
72 Drop
: Truncation
:= Error
) return Super_String
;
73 -- Note the additional parameter Max_Length, which specifies the maximum
74 -- length setting of the resulting Super_String value.
76 -- The following procedures have declarations (and semantics) that are
77 -- exactly analogous to those declared in Ada.Strings.Wide_Bounded.
79 function Super_To_String
(Source
: Super_String
) return Wide_String;
81 procedure Set_Super_String
82 (Target
: out Super_String
;
84 Drop
: Truncation
:= Error
);
89 Drop
: Truncation
:= Error
) return Super_String
;
94 Drop
: Truncation
:= Error
) return Super_String
;
99 Drop
: Truncation
:= Error
) return Super_String
;
101 function Super_Append
102 (Left
: Super_String
;
103 Right
: Wide_Character;
104 Drop
: Truncation
:= Error
) return Super_String
;
106 function Super_Append
107 (Left
: Wide_Character;
108 Right
: Super_String
;
109 Drop
: Truncation
:= Error
) return Super_String
;
111 procedure Super_Append
112 (Source
: in out Super_String
;
113 New_Item
: Super_String
;
114 Drop
: Truncation
:= Error
);
116 procedure Super_Append
117 (Source
: in out Super_String
;
118 New_Item
: Wide_String;
119 Drop
: Truncation
:= Error
);
121 procedure Super_Append
122 (Source
: in out Super_String
;
123 New_Item
: Wide_Character;
124 Drop
: Truncation
:= Error
);
127 (Left
: Super_String
;
128 Right
: Super_String
) return Super_String
;
131 (Left
: Super_String
;
132 Right
: Wide_String) return Super_String
;
136 Right
: Super_String
) return Super_String
;
139 (Left
: Super_String
;
140 Right
: Wide_Character) return Super_String
;
143 (Left
: Wide_Character;
144 Right
: Super_String
) return Super_String
;
146 function Super_Element
147 (Source
: Super_String
;
148 Index
: Positive) return Wide_Character;
150 procedure Super_Replace_Element
151 (Source
: in out Super_String
;
153 By
: Wide_Character);
156 (Source
: Super_String
;
158 High
: Natural) return Wide_String;
161 (Source
: Super_String
;
163 High
: Natural) return Super_String
;
165 procedure Super_Slice
166 (Source
: Super_String
;
167 Target
: out Super_String
;
172 (Left
: Super_String
;
173 Right
: Super_String
) return Boolean;
176 (Left
: Super_String
;
177 Right
: Super_String
) return Boolean renames "=";
180 (Left
: Super_String
;
181 Right
: Wide_String) return Boolean;
185 Right
: Super_String
) return Boolean;
188 (Left
: Super_String
;
189 Right
: Super_String
) return Boolean;
192 (Left
: Super_String
;
193 Right
: Wide_String) return Boolean;
197 Right
: Super_String
) return Boolean;
199 function Less_Or_Equal
200 (Left
: Super_String
;
201 Right
: Super_String
) return Boolean;
203 function Less_Or_Equal
204 (Left
: Super_String
;
205 Right
: Wide_String) return Boolean;
207 function Less_Or_Equal
209 Right
: Super_String
) return Boolean;
212 (Left
: Super_String
;
213 Right
: Super_String
) return Boolean;
216 (Left
: Super_String
;
217 Right
: Wide_String) return Boolean;
221 Right
: Super_String
) return Boolean;
223 function Greater_Or_Equal
224 (Left
: Super_String
;
225 Right
: Super_String
) return Boolean;
227 function Greater_Or_Equal
228 (Left
: Super_String
;
229 Right
: Wide_String) return Boolean;
231 function Greater_Or_Equal
233 Right
: Super_String
) return Boolean;
235 ----------------------
236 -- Search Functions --
237 ----------------------
240 (Source
: Super_String
;
241 Pattern
: Wide_String;
242 Going
: Direction
:= Forward
;
243 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
247 (Source
: Super_String
;
248 Pattern
: Wide_String;
249 Going
: Direction
:= Forward
;
250 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
253 (Source
: Super_String
;
254 Set
: Wide_Maps
.Wide_Character_Set
;
255 Test
: Membership
:= Inside
;
256 Going
: Direction
:= Forward
) return Natural;
259 (Source
: Super_String
;
260 Pattern
: Wide_String;
262 Going
: Direction
:= Forward
;
263 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
267 (Source
: Super_String
;
268 Pattern
: Wide_String;
270 Going
: Direction
:= Forward
;
271 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
274 (Source
: Super_String
;
275 Set
: Wide_Maps
.Wide_Character_Set
;
277 Test
: Membership
:= Inside
;
278 Going
: Direction
:= Forward
) return Natural;
280 function Super_Index_Non_Blank
281 (Source
: Super_String
;
282 Going
: Direction
:= Forward
) return Natural;
284 function Super_Index_Non_Blank
285 (Source
: Super_String
;
287 Going
: Direction
:= Forward
) return Natural;
290 (Source
: Super_String
;
291 Pattern
: Wide_String;
292 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
296 (Source
: Super_String
;
297 Pattern
: Wide_String;
298 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
301 (Source
: Super_String
;
302 Set
: Wide_Maps
.Wide_Character_Set
) return Natural;
304 procedure Super_Find_Token
305 (Source
: Super_String
;
306 Set
: Wide_Maps
.Wide_Character_Set
;
309 First
: out Positive;
312 procedure Super_Find_Token
313 (Source
: Super_String
;
314 Set
: Wide_Maps
.Wide_Character_Set
;
316 First
: out Positive;
319 ------------------------------------
320 -- String Translation Subprograms --
321 ------------------------------------
323 function Super_Translate
324 (Source
: Super_String
;
325 Mapping
: Wide_Maps
.Wide_Character_Mapping
) return Super_String
;
327 procedure Super_Translate
328 (Source
: in out Super_String
;
329 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
331 function Super_Translate
332 (Source
: Super_String
;
333 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Super_String
;
335 procedure Super_Translate
336 (Source
: in out Super_String
;
337 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
339 ---------------------------------------
340 -- String Transformation Subprograms --
341 ---------------------------------------
343 function Super_Replace_Slice
344 (Source
: Super_String
;
348 Drop
: Truncation
:= Error
) return Super_String
;
350 procedure Super_Replace_Slice
351 (Source
: in out Super_String
;
355 Drop
: Truncation
:= Error
);
357 function Super_Insert
358 (Source
: Super_String
;
360 New_Item
: Wide_String;
361 Drop
: Truncation
:= Error
) return Super_String
;
363 procedure Super_Insert
364 (Source
: in out Super_String
;
366 New_Item
: Wide_String;
367 Drop
: Truncation
:= Error
);
369 function Super_Overwrite
370 (Source
: Super_String
;
372 New_Item
: Wide_String;
373 Drop
: Truncation
:= Error
) return Super_String
;
375 procedure Super_Overwrite
376 (Source
: in out Super_String
;
378 New_Item
: Wide_String;
379 Drop
: Truncation
:= Error
);
381 function Super_Delete
382 (Source
: Super_String
;
384 Through
: Natural) return Super_String
;
386 procedure Super_Delete
387 (Source
: in out Super_String
;
391 ---------------------------------
392 -- String Selector Subprograms --
393 ---------------------------------
396 (Source
: Super_String
;
397 Side
: Trim_End
) return Super_String
;
400 (Source
: in out Super_String
;
404 (Source
: Super_String
;
405 Left
: Wide_Maps
.Wide_Character_Set
;
406 Right
: Wide_Maps
.Wide_Character_Set
) return Super_String
;
409 (Source
: in out Super_String
;
410 Left
: Wide_Maps
.Wide_Character_Set
;
411 Right
: Wide_Maps
.Wide_Character_Set
);
414 (Source
: Super_String
;
416 Pad
: Wide_Character := Wide_Space
;
417 Drop
: Truncation
:= Error
) return Super_String
;
420 (Source
: in out Super_String
;
422 Pad
: Wide_Character := Wide_Space
;
423 Drop
: Truncation
:= Error
);
426 (Source
: Super_String
;
428 Pad
: Wide_Character := Wide_Space
;
429 Drop
: Truncation
:= Error
) return Super_String
;
432 (Source
: in out Super_String
;
434 Pad
: Wide_Character := Wide_Space
;
435 Drop
: Truncation
:= Error
);
437 ------------------------------------
438 -- String Constructor Subprograms --
439 ------------------------------------
441 -- Note: in some of the following routines, there is an extra parameter
442 -- Max_Length which specifies the value of the maximum length for the
443 -- resulting Super_String value.
447 Right
: Wide_Character;
448 Max_Length
: Positive) return Super_String
;
449 -- Note the additional parameter Max_Length
454 Max_Length
: Positive) return Super_String
;
455 -- Note the additional parameter Max_Length
459 Right
: Super_String
) return Super_String
;
461 function Super_Replicate
463 Item
: Wide_Character;
464 Drop
: Truncation
:= Error
;
465 Max_Length
: Positive) return Super_String
;
466 -- Note the additional parameter Max_Length
468 function Super_Replicate
471 Drop
: Truncation
:= Error
;
472 Max_Length
: Positive) return Super_String
;
473 -- Note the additional parameter Max_Length
475 function Super_Replicate
478 Drop
: Truncation
:= Error
) return Super_String
;
481 -- Pragma Inline declarations
484 pragma Inline
(Less
);
485 pragma Inline
(Less_Or_Equal
);
486 pragma Inline
(Greater
);
487 pragma Inline
(Greater_Or_Equal
);
488 pragma Inline
(Concat
);
489 pragma Inline
(Super_Count
);
490 pragma Inline
(Super_Element
);
491 pragma Inline
(Super_Find_Token
);
492 pragma Inline
(Super_Index
);
493 pragma Inline
(Super_Index_Non_Blank
);
494 pragma Inline
(Super_Length
);
495 pragma Inline
(Super_Replace_Element
);
496 pragma Inline
(Super_Slice
);
497 pragma Inline
(Super_To_String
);
499 end Ada
.Strings
.Wide_Superbounded
;