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-2009, 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 Super_String
(Max_Length
: Positive) is record
45 Current_Length
: Natural := 0;
46 Data
: String (1 .. Max_Length
) := (others => ASCII
.NUL
);
48 -- Type Bounded_String in Ada.Strings.Bounded.Generic_Bounded_Length is
49 -- derived from this type, with the constraint of the maximum length.
51 -- The subprograms defined for Super_String are similar to those
52 -- defined for Bounded_String, except that they have different names, so
53 -- that they can be renamed in Ada.Strings.Bounded.Generic_Bounded_Length.
55 function Super_Length
(Source
: Super_String
) return Natural;
57 --------------------------------------------------------
58 -- Conversion, Concatenation, and Selection Functions --
59 --------------------------------------------------------
61 function To_Super_String
64 Drop
: Truncation
:= Error
) return Super_String
;
65 -- Note the additional parameter Max_Length, which specifies the maximum
66 -- length setting of the resulting Super_String value.
68 -- The following procedures have declarations (and semantics) that are
69 -- exactly analogous to those declared in Ada.Strings.Bounded.
71 function Super_To_String
(Source
: Super_String
) return String;
73 procedure Set_Super_String
74 (Target
: out Super_String
;
76 Drop
: Truncation
:= Error
);
81 Drop
: Truncation
:= Error
) return Super_String
;
86 Drop
: Truncation
:= Error
) return Super_String
;
91 Drop
: Truncation
:= Error
) return Super_String
;
96 Drop
: Truncation
:= Error
) return Super_String
;
100 Right
: Super_String
;
101 Drop
: Truncation
:= Error
) return Super_String
;
103 procedure Super_Append
104 (Source
: in out Super_String
;
105 New_Item
: Super_String
;
106 Drop
: Truncation
:= Error
);
108 procedure Super_Append
109 (Source
: in out Super_String
;
111 Drop
: Truncation
:= Error
);
113 procedure Super_Append
114 (Source
: in out Super_String
;
115 New_Item
: Character;
116 Drop
: Truncation
:= Error
);
119 (Left
: Super_String
;
120 Right
: Super_String
) return Super_String
;
123 (Left
: Super_String
;
124 Right
: String) return Super_String
;
128 Right
: Super_String
) return Super_String
;
131 (Left
: Super_String
;
132 Right
: Character) return Super_String
;
136 Right
: Super_String
) return Super_String
;
138 function Super_Element
139 (Source
: Super_String
;
140 Index
: Positive) return Character;
142 procedure Super_Replace_Element
143 (Source
: in out Super_String
;
148 (Source
: Super_String
;
150 High
: Natural) return String;
153 (Source
: Super_String
;
155 High
: Natural) return Super_String
;
157 procedure Super_Slice
158 (Source
: Super_String
;
159 Target
: out Super_String
;
164 (Left
: Super_String
;
165 Right
: Super_String
) return Boolean;
168 (Left
: Super_String
;
169 Right
: Super_String
) return Boolean renames "=";
172 (Left
: Super_String
;
173 Right
: String) return Boolean;
177 Right
: Super_String
) return Boolean;
180 (Left
: Super_String
;
181 Right
: Super_String
) return Boolean;
184 (Left
: Super_String
;
185 Right
: String) return Boolean;
189 Right
: Super_String
) return Boolean;
191 function Less_Or_Equal
192 (Left
: Super_String
;
193 Right
: Super_String
) return Boolean;
195 function Less_Or_Equal
196 (Left
: Super_String
;
197 Right
: String) return Boolean;
199 function Less_Or_Equal
201 Right
: Super_String
) return Boolean;
204 (Left
: Super_String
;
205 Right
: Super_String
) return Boolean;
208 (Left
: Super_String
;
209 Right
: String) return Boolean;
213 Right
: Super_String
) return Boolean;
215 function Greater_Or_Equal
216 (Left
: Super_String
;
217 Right
: Super_String
) return Boolean;
219 function Greater_Or_Equal
220 (Left
: Super_String
;
221 Right
: String) return Boolean;
223 function Greater_Or_Equal
225 Right
: Super_String
) return Boolean;
227 ----------------------
228 -- Search Functions --
229 ----------------------
232 (Source
: Super_String
;
234 Going
: Direction
:= Forward
;
235 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
238 (Source
: Super_String
;
240 Going
: Direction
:= Forward
;
241 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
244 (Source
: Super_String
;
245 Set
: Maps
.Character_Set
;
246 Test
: Membership
:= Inside
;
247 Going
: Direction
:= Forward
) return Natural;
250 (Source
: Super_String
;
253 Going
: Direction
:= Forward
;
254 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
257 (Source
: Super_String
;
260 Going
: Direction
:= Forward
;
261 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
264 (Source
: Super_String
;
265 Set
: Maps
.Character_Set
;
267 Test
: Membership
:= Inside
;
268 Going
: Direction
:= Forward
) return Natural;
270 function Super_Index_Non_Blank
271 (Source
: Super_String
;
272 Going
: Direction
:= Forward
) return Natural;
274 function Super_Index_Non_Blank
275 (Source
: Super_String
;
277 Going
: Direction
:= Forward
) return Natural;
280 (Source
: Super_String
;
282 Mapping
: Maps
.Character_Mapping
:= Maps
.Identity
) return Natural;
285 (Source
: Super_String
;
287 Mapping
: Maps
.Character_Mapping_Function
) return Natural;
290 (Source
: Super_String
;
291 Set
: Maps
.Character_Set
) return Natural;
293 procedure Super_Find_Token
294 (Source
: Super_String
;
295 Set
: Maps
.Character_Set
;
297 First
: out Positive;
300 ------------------------------------
301 -- String Translation Subprograms --
302 ------------------------------------
304 function Super_Translate
305 (Source
: Super_String
;
306 Mapping
: Maps
.Character_Mapping
) return Super_String
;
308 procedure Super_Translate
309 (Source
: in out Super_String
;
310 Mapping
: Maps
.Character_Mapping
);
312 function Super_Translate
313 (Source
: Super_String
;
314 Mapping
: Maps
.Character_Mapping_Function
) return Super_String
;
316 procedure Super_Translate
317 (Source
: in out Super_String
;
318 Mapping
: Maps
.Character_Mapping_Function
);
320 ---------------------------------------
321 -- String Transformation Subprograms --
322 ---------------------------------------
324 function Super_Replace_Slice
325 (Source
: Super_String
;
329 Drop
: Truncation
:= Error
) return Super_String
;
331 procedure Super_Replace_Slice
332 (Source
: in out Super_String
;
336 Drop
: Truncation
:= Error
);
338 function Super_Insert
339 (Source
: Super_String
;
342 Drop
: Truncation
:= Error
) return Super_String
;
344 procedure Super_Insert
345 (Source
: in out Super_String
;
348 Drop
: Truncation
:= Error
);
350 function Super_Overwrite
351 (Source
: Super_String
;
354 Drop
: Truncation
:= Error
) return Super_String
;
356 procedure Super_Overwrite
357 (Source
: in out Super_String
;
360 Drop
: Truncation
:= Error
);
362 function Super_Delete
363 (Source
: Super_String
;
365 Through
: Natural) return Super_String
;
367 procedure Super_Delete
368 (Source
: in out Super_String
;
372 ---------------------------------
373 -- String Selector Subprograms --
374 ---------------------------------
377 (Source
: Super_String
;
378 Side
: Trim_End
) return Super_String
;
381 (Source
: in out Super_String
;
385 (Source
: Super_String
;
386 Left
: Maps
.Character_Set
;
387 Right
: Maps
.Character_Set
) return Super_String
;
390 (Source
: in out Super_String
;
391 Left
: Maps
.Character_Set
;
392 Right
: Maps
.Character_Set
);
395 (Source
: Super_String
;
397 Pad
: Character := Space
;
398 Drop
: Truncation
:= Error
) return Super_String
;
401 (Source
: in out Super_String
;
403 Pad
: Character := Space
;
404 Drop
: Truncation
:= Error
);
407 (Source
: Super_String
;
409 Pad
: Character := Space
;
410 Drop
: Truncation
:= Error
) return Super_String
;
413 (Source
: in out Super_String
;
415 Pad
: Character := Space
;
416 Drop
: Truncation
:= Error
);
418 ------------------------------------
419 -- String Constructor Subprograms --
420 ------------------------------------
422 -- Note: in some of the following routines, there is an extra parameter
423 -- Max_Length which specifies the value of the maximum length for the
424 -- resulting Super_String value.
429 Max_Length
: Positive) return Super_String
;
430 -- Note the additional parameter Max_Length
435 Max_Length
: Positive) return Super_String
;
436 -- Note the additional parameter Max_Length
440 Right
: Super_String
) return Super_String
;
442 function Super_Replicate
445 Drop
: Truncation
:= Error
;
446 Max_Length
: Positive) return Super_String
;
447 -- Note the additional parameter Max_Length
449 function Super_Replicate
452 Drop
: Truncation
:= Error
;
453 Max_Length
: Positive) return Super_String
;
454 -- Note the additional parameter Max_Length
456 function Super_Replicate
459 Drop
: Truncation
:= Error
) return Super_String
;
462 -- Pragma Inline declarations
465 pragma Inline
(Less
);
466 pragma Inline
(Less_Or_Equal
);
467 pragma Inline
(Greater
);
468 pragma Inline
(Greater_Or_Equal
);
469 pragma Inline
(Concat
);
470 pragma Inline
(Super_Count
);
471 pragma Inline
(Super_Element
);
472 pragma Inline
(Super_Find_Token
);
473 pragma Inline
(Super_Index
);
474 pragma Inline
(Super_Index_Non_Blank
);
475 pragma Inline
(Super_Length
);
476 pragma Inline
(Super_Replace_Element
);
477 pragma Inline
(Super_Slice
);
478 pragma Inline
(Super_To_String
);
480 end Ada
.Strings
.Superbounded
;