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-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.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 type Super_String
(Max_Length
: Positive) is record
48 Current_Length
: Natural := 0;
49 Data
: Wide_String (1 .. Max_Length
) := (others => Wide_NUL
);
51 -- Ada.Strings.Wide_Bounded.Generic_Bounded_Length.Wide_Bounded_String is
52 -- derived from this type, with the constraint of the maximum length.
54 -- The subprograms defined for Super_String are similar to those defined
55 -- for Bounded_Wide_String, except that they have different names, so that
56 -- they can be renamed in Ada.Strings.Wide_Bounded.Generic_Bounded_Length.
58 function Super_Length
(Source
: Super_String
) return Natural;
60 --------------------------------------------------------
61 -- Conversion, Concatenation, and Selection Functions --
62 --------------------------------------------------------
64 function To_Super_String
65 (Source
: Wide_String;
67 Drop
: Truncation
:= Error
) return Super_String
;
68 -- Note the additional parameter Max_Length, which specifies the maximum
69 -- length setting of the resulting Super_String value.
71 -- The following procedures have declarations (and semantics) that are
72 -- exactly analogous to those declared in Ada.Strings.Wide_Bounded.
74 function Super_To_String
(Source
: Super_String
) return Wide_String;
76 procedure Set_Super_String
77 (Target
: out Super_String
;
79 Drop
: Truncation
:= Error
);
84 Drop
: Truncation
:= Error
) return Super_String
;
89 Drop
: Truncation
:= Error
) return Super_String
;
94 Drop
: Truncation
:= Error
) return Super_String
;
98 Right
: Wide_Character;
99 Drop
: Truncation
:= Error
) return Super_String
;
101 function Super_Append
102 (Left
: Wide_Character;
103 Right
: Super_String
;
104 Drop
: Truncation
:= Error
) return Super_String
;
106 procedure Super_Append
107 (Source
: in out Super_String
;
108 New_Item
: Super_String
;
109 Drop
: Truncation
:= Error
);
111 procedure Super_Append
112 (Source
: in out Super_String
;
113 New_Item
: Wide_String;
114 Drop
: Truncation
:= Error
);
116 procedure Super_Append
117 (Source
: in out Super_String
;
118 New_Item
: Wide_Character;
119 Drop
: Truncation
:= Error
);
122 (Left
: Super_String
;
123 Right
: Super_String
) return Super_String
;
126 (Left
: Super_String
;
127 Right
: Wide_String) return Super_String
;
131 Right
: Super_String
) return Super_String
;
134 (Left
: Super_String
;
135 Right
: Wide_Character) return Super_String
;
138 (Left
: Wide_Character;
139 Right
: Super_String
) return Super_String
;
141 function Super_Element
142 (Source
: Super_String
;
143 Index
: Positive) return Wide_Character;
145 procedure Super_Replace_Element
146 (Source
: in out Super_String
;
148 By
: Wide_Character);
151 (Source
: Super_String
;
153 High
: Natural) return Wide_String;
156 (Source
: Super_String
;
158 High
: Natural) return Super_String
;
160 procedure Super_Slice
161 (Source
: Super_String
;
162 Target
: out Super_String
;
167 (Left
: Super_String
;
168 Right
: Super_String
) return Boolean;
171 (Left
: Super_String
;
172 Right
: Super_String
) return Boolean renames "=";
175 (Left
: Super_String
;
176 Right
: Wide_String) return Boolean;
180 Right
: Super_String
) return Boolean;
183 (Left
: Super_String
;
184 Right
: Super_String
) return Boolean;
187 (Left
: Super_String
;
188 Right
: Wide_String) return Boolean;
192 Right
: Super_String
) return Boolean;
194 function Less_Or_Equal
195 (Left
: Super_String
;
196 Right
: Super_String
) return Boolean;
198 function Less_Or_Equal
199 (Left
: Super_String
;
200 Right
: Wide_String) return Boolean;
202 function Less_Or_Equal
204 Right
: Super_String
) return Boolean;
207 (Left
: Super_String
;
208 Right
: Super_String
) return Boolean;
211 (Left
: Super_String
;
212 Right
: Wide_String) return Boolean;
216 Right
: Super_String
) return Boolean;
218 function Greater_Or_Equal
219 (Left
: Super_String
;
220 Right
: Super_String
) return Boolean;
222 function Greater_Or_Equal
223 (Left
: Super_String
;
224 Right
: Wide_String) return Boolean;
226 function Greater_Or_Equal
228 Right
: Super_String
) return Boolean;
230 ----------------------
231 -- Search Functions --
232 ----------------------
235 (Source
: Super_String
;
236 Pattern
: Wide_String;
237 Going
: Direction
:= Forward
;
238 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
242 (Source
: Super_String
;
243 Pattern
: Wide_String;
244 Going
: Direction
:= Forward
;
245 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
248 (Source
: Super_String
;
249 Set
: Wide_Maps
.Wide_Character_Set
;
250 Test
: Membership
:= Inside
;
251 Going
: Direction
:= Forward
) return Natural;
254 (Source
: Super_String
;
255 Pattern
: Wide_String;
257 Going
: Direction
:= Forward
;
258 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
262 (Source
: Super_String
;
263 Pattern
: Wide_String;
265 Going
: Direction
:= Forward
;
266 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
269 (Source
: Super_String
;
270 Set
: Wide_Maps
.Wide_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
;
286 Pattern
: Wide_String;
287 Mapping
: Wide_Maps
.Wide_Character_Mapping
:= Wide_Maps
.Identity
)
291 (Source
: Super_String
;
292 Pattern
: Wide_String;
293 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Natural;
296 (Source
: Super_String
;
297 Set
: Wide_Maps
.Wide_Character_Set
) return Natural;
299 procedure Super_Find_Token
300 (Source
: Super_String
;
301 Set
: Wide_Maps
.Wide_Character_Set
;
303 First
: out Positive;
306 ------------------------------------
307 -- String Translation Subprograms --
308 ------------------------------------
310 function Super_Translate
311 (Source
: Super_String
;
312 Mapping
: Wide_Maps
.Wide_Character_Mapping
) return Super_String
;
314 procedure Super_Translate
315 (Source
: in out Super_String
;
316 Mapping
: Wide_Maps
.Wide_Character_Mapping
);
318 function Super_Translate
319 (Source
: Super_String
;
320 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
) return Super_String
;
322 procedure Super_Translate
323 (Source
: in out Super_String
;
324 Mapping
: Wide_Maps
.Wide_Character_Mapping_Function
);
326 ---------------------------------------
327 -- String Transformation Subprograms --
328 ---------------------------------------
330 function Super_Replace_Slice
331 (Source
: Super_String
;
335 Drop
: Truncation
:= Error
) return Super_String
;
337 procedure Super_Replace_Slice
338 (Source
: in out Super_String
;
342 Drop
: Truncation
:= Error
);
344 function Super_Insert
345 (Source
: Super_String
;
347 New_Item
: Wide_String;
348 Drop
: Truncation
:= Error
) return Super_String
;
350 procedure Super_Insert
351 (Source
: in out Super_String
;
353 New_Item
: Wide_String;
354 Drop
: Truncation
:= Error
);
356 function Super_Overwrite
357 (Source
: Super_String
;
359 New_Item
: Wide_String;
360 Drop
: Truncation
:= Error
) return Super_String
;
362 procedure Super_Overwrite
363 (Source
: in out Super_String
;
365 New_Item
: Wide_String;
366 Drop
: Truncation
:= Error
);
368 function Super_Delete
369 (Source
: Super_String
;
371 Through
: Natural) return Super_String
;
373 procedure Super_Delete
374 (Source
: in out Super_String
;
378 ---------------------------------
379 -- String Selector Subprograms --
380 ---------------------------------
383 (Source
: Super_String
;
384 Side
: Trim_End
) return Super_String
;
387 (Source
: in out Super_String
;
391 (Source
: Super_String
;
392 Left
: Wide_Maps
.Wide_Character_Set
;
393 Right
: Wide_Maps
.Wide_Character_Set
) return Super_String
;
396 (Source
: in out Super_String
;
397 Left
: Wide_Maps
.Wide_Character_Set
;
398 Right
: Wide_Maps
.Wide_Character_Set
);
401 (Source
: Super_String
;
403 Pad
: Wide_Character := Wide_Space
;
404 Drop
: Truncation
:= Error
) return Super_String
;
407 (Source
: in out Super_String
;
409 Pad
: Wide_Character := Wide_Space
;
410 Drop
: Truncation
:= Error
);
413 (Source
: Super_String
;
415 Pad
: Wide_Character := Wide_Space
;
416 Drop
: Truncation
:= Error
) return Super_String
;
419 (Source
: in out Super_String
;
421 Pad
: Wide_Character := Wide_Space
;
422 Drop
: Truncation
:= Error
);
424 ------------------------------------
425 -- String Constructor Subprograms --
426 ------------------------------------
428 -- Note: in some of the following routines, there is an extra parameter
429 -- Max_Length which specifies the value of the maximum length for the
430 -- resulting Super_String value.
434 Right
: Wide_Character;
435 Max_Length
: Positive) return Super_String
;
436 -- Note the additional parameter Max_Length
441 Max_Length
: Positive) return Super_String
;
442 -- Note the additional parameter Max_Length
446 Right
: Super_String
) return Super_String
;
448 function Super_Replicate
450 Item
: Wide_Character;
451 Drop
: Truncation
:= Error
;
452 Max_Length
: Positive) return Super_String
;
453 -- Note the additional parameter Max_Length
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
) return Super_String
;
468 -- Pragma Inline declarations
471 pragma Inline
(Less
);
472 pragma Inline
(Less_Or_Equal
);
473 pragma Inline
(Greater
);
474 pragma Inline
(Greater_Or_Equal
);
475 pragma Inline
(Concat
);
476 pragma Inline
(Super_Count
);
477 pragma Inline
(Super_Element
);
478 pragma Inline
(Super_Find_Token
);
479 pragma Inline
(Super_Index
);
480 pragma Inline
(Super_Index_Non_Blank
);
481 pragma Inline
(Super_Length
);
482 pragma Inline
(Super_Replace_Element
);
483 pragma Inline
(Super_Slice
);
484 pragma Inline
(Super_To_String
);
486 end Ada
.Strings
.Wide_Superbounded
;