OSDN Git Service

2006-10-31 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-stzunb.ads
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 _ U N B O U N D E D       --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- GNAT was originally developed  by the GNAT team at  New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
35 --                                                                          --
36 ------------------------------------------------------------------------------
37
38 with Ada.Strings.Wide_Wide_Maps;
39 with Ada.Finalization;
40
41 package Ada.Strings.Wide_Wide_Unbounded is
42    pragma Preelaborate;
43
44    type Unbounded_Wide_Wide_String is private;
45    pragma Preelaborable_Initialization (Unbounded_Wide_Wide_String);
46
47    Null_Unbounded_Wide_Wide_String : constant Unbounded_Wide_Wide_String;
48
49    function Length (Source : Unbounded_Wide_Wide_String) return Natural;
50
51    type Wide_Wide_String_Access is access all Wide_Wide_String;
52
53    procedure Free (X : in out Wide_Wide_String_Access);
54
55    --------------------------------------------------------
56    -- Conversion, Concatenation, and Selection Functions --
57    --------------------------------------------------------
58
59    function To_Unbounded_Wide_Wide_String
60      (Source : Wide_Wide_String) return Unbounded_Wide_Wide_String;
61
62    function To_Unbounded_Wide_Wide_String
63      (Length : Natural) return Unbounded_Wide_Wide_String;
64
65    function To_Wide_Wide_String
66      (Source : Unbounded_Wide_Wide_String) return Wide_Wide_String;
67
68    procedure Set_Unbounded_Wide_Wide_String
69      (Target : out Unbounded_Wide_Wide_String;
70       Source : Wide_Wide_String);
71    pragma Ada_05 (Set_Unbounded_Wide_Wide_String);
72
73    procedure Append
74      (Source   : in out Unbounded_Wide_Wide_String;
75       New_Item : Unbounded_Wide_Wide_String);
76
77    procedure Append
78      (Source   : in out Unbounded_Wide_Wide_String;
79       New_Item : Wide_Wide_String);
80
81    procedure Append
82      (Source   : in out Unbounded_Wide_Wide_String;
83       New_Item : Wide_Wide_Character);
84
85    function "&"
86      (Left  : Unbounded_Wide_Wide_String;
87       Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String;
88
89    function "&"
90      (Left  : Unbounded_Wide_Wide_String;
91       Right : Wide_Wide_String) return Unbounded_Wide_Wide_String;
92
93    function "&"
94      (Left  : Wide_Wide_String;
95       Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String;
96
97    function "&"
98      (Left  : Unbounded_Wide_Wide_String;
99       Right : Wide_Wide_Character) return Unbounded_Wide_Wide_String;
100
101    function "&"
102      (Left  : Wide_Wide_Character;
103       Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String;
104
105    function Element
106      (Source : Unbounded_Wide_Wide_String;
107       Index  : Positive) return Wide_Wide_Character;
108
109    procedure Replace_Element
110      (Source : in out Unbounded_Wide_Wide_String;
111       Index  : Positive;
112       By     : Wide_Wide_Character);
113
114    function Slice
115      (Source : Unbounded_Wide_Wide_String;
116       Low    : Positive;
117       High   : Natural) return Wide_Wide_String;
118
119    function Unbounded_Slice
120      (Source : Unbounded_Wide_Wide_String;
121       Low    : Positive;
122       High   : Natural) return Unbounded_Wide_Wide_String;
123       pragma Ada_05 (Unbounded_Slice);
124
125    procedure Unbounded_Slice
126      (Source : Unbounded_Wide_Wide_String;
127       Target : out Unbounded_Wide_Wide_String;
128       Low    : Positive;
129       High   : Natural);
130       pragma Ada_05 (Unbounded_Slice);
131
132    function "="
133      (Left  : Unbounded_Wide_Wide_String;
134       Right : Unbounded_Wide_Wide_String) return Boolean;
135
136    function "="
137      (Left  : Unbounded_Wide_Wide_String;
138       Right : Wide_Wide_String) return Boolean;
139
140    function "="
141      (Left  : Wide_Wide_String;
142       Right : Unbounded_Wide_Wide_String) return Boolean;
143
144    function "<"
145      (Left  : Unbounded_Wide_Wide_String;
146       Right : Unbounded_Wide_Wide_String) return Boolean;
147
148    function "<"
149      (Left  : Unbounded_Wide_Wide_String;
150       Right : Wide_Wide_String) return Boolean;
151
152    function "<"
153      (Left  : Wide_Wide_String;
154       Right : Unbounded_Wide_Wide_String) return Boolean;
155
156    function "<="
157      (Left  : Unbounded_Wide_Wide_String;
158       Right : Unbounded_Wide_Wide_String) return Boolean;
159
160    function "<="
161      (Left  : Unbounded_Wide_Wide_String;
162       Right : Wide_Wide_String) return Boolean;
163
164    function "<="
165      (Left  : Wide_Wide_String;
166       Right : Unbounded_Wide_Wide_String) return Boolean;
167
168    function ">"
169      (Left  : Unbounded_Wide_Wide_String;
170       Right : Unbounded_Wide_Wide_String) return Boolean;
171
172    function ">"
173      (Left  : Unbounded_Wide_Wide_String;
174       Right : Wide_Wide_String) return Boolean;
175
176    function ">"
177      (Left  : Wide_Wide_String;
178       Right : Unbounded_Wide_Wide_String) return Boolean;
179
180    function ">="
181      (Left  : Unbounded_Wide_Wide_String;
182       Right : Unbounded_Wide_Wide_String) return Boolean;
183
184    function ">="
185      (Left  : Unbounded_Wide_Wide_String;
186       Right : Wide_Wide_String) return Boolean;
187
188    function ">="
189      (Left  : Wide_Wide_String;
190       Right : Unbounded_Wide_Wide_String) return Boolean;
191
192    ------------------------
193    -- Search Subprograms --
194    ------------------------
195
196    function Index
197      (Source  : Unbounded_Wide_Wide_String;
198       Pattern : Wide_Wide_String;
199       Going   : Direction := Forward;
200       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
201                   Wide_Wide_Maps.Identity)
202       return Natural;
203
204    function Index
205      (Source  : Unbounded_Wide_Wide_String;
206       Pattern : Wide_Wide_String;
207       Going   : Direction := Forward;
208       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
209       return Natural;
210
211    function Index
212      (Source : Unbounded_Wide_Wide_String;
213       Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
214       Test   : Membership := Inside;
215       Going  : Direction  := Forward) return Natural;
216
217    function Index
218      (Source  : Unbounded_Wide_Wide_String;
219       Pattern : Wide_Wide_String;
220       From    : Positive;
221       Going   : Direction := Forward;
222       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
223                   Wide_Wide_Maps.Identity)
224       return Natural;
225    pragma Ada_05 (Index);
226
227    function Index
228      (Source  : Unbounded_Wide_Wide_String;
229       Pattern : Wide_Wide_String;
230       From    : Positive;
231       Going   : Direction := Forward;
232       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
233       return Natural;
234    pragma Ada_05 (Index);
235
236    function Index
237      (Source : Unbounded_Wide_Wide_String;
238       Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
239       From   : Positive;
240       Test   : Membership := Inside;
241       Going  : Direction := Forward) return Natural;
242    pragma Ada_05 (Index);
243
244    function Index_Non_Blank
245      (Source : Unbounded_Wide_Wide_String;
246       Going  : Direction := Forward) return Natural;
247
248    function Index_Non_Blank
249      (Source : Unbounded_Wide_Wide_String;
250       From   : Positive;
251       Going  : Direction := Forward) return Natural;
252    pragma Ada_05 (Index_Non_Blank);
253
254    function Count
255      (Source  : Unbounded_Wide_Wide_String;
256       Pattern : Wide_Wide_String;
257       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
258                   Wide_Wide_Maps.Identity)
259       return Natural;
260
261    function Count
262      (Source  : Unbounded_Wide_Wide_String;
263       Pattern : Wide_Wide_String;
264       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
265       return Natural;
266
267    function Count
268      (Source : Unbounded_Wide_Wide_String;
269       Set    : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural;
270
271    procedure Find_Token
272      (Source : Unbounded_Wide_Wide_String;
273       Set    : Wide_Wide_Maps.Wide_Wide_Character_Set;
274       Test   : Membership;
275       First  : out Positive;
276       Last   : out Natural);
277
278    ------------------------------------
279    -- String Translation Subprograms --
280    ------------------------------------
281
282    function Translate
283      (Source  : Unbounded_Wide_Wide_String;
284       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
285       return Unbounded_Wide_Wide_String;
286
287    procedure Translate
288      (Source  : in out Unbounded_Wide_Wide_String;
289       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping);
290
291    function Translate
292      (Source  : Unbounded_Wide_Wide_String;
293       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
294       return Unbounded_Wide_Wide_String;
295
296    procedure Translate
297      (Source  : in out Unbounded_Wide_Wide_String;
298       Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function);
299
300    ---------------------------------------
301    -- String Transformation Subprograms --
302    ---------------------------------------
303
304    function Replace_Slice
305      (Source : Unbounded_Wide_Wide_String;
306       Low    : Positive;
307       High   : Natural;
308       By     : Wide_Wide_String) return Unbounded_Wide_Wide_String;
309
310    procedure Replace_Slice
311      (Source : in out Unbounded_Wide_Wide_String;
312       Low    : Positive;
313       High   : Natural;
314       By     : Wide_Wide_String);
315
316    function Insert
317      (Source   : Unbounded_Wide_Wide_String;
318       Before   : Positive;
319       New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String;
320
321    procedure Insert
322      (Source   : in out Unbounded_Wide_Wide_String;
323       Before   : Positive;
324       New_Item : Wide_Wide_String);
325
326    function Overwrite
327      (Source   : Unbounded_Wide_Wide_String;
328       Position : Positive;
329       New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String;
330
331    procedure Overwrite
332      (Source   : in out Unbounded_Wide_Wide_String;
333       Position : Positive;
334       New_Item : Wide_Wide_String);
335
336    function Delete
337      (Source  : Unbounded_Wide_Wide_String;
338       From    : Positive;
339       Through : Natural) return Unbounded_Wide_Wide_String;
340
341    procedure Delete
342      (Source  : in out Unbounded_Wide_Wide_String;
343       From    : Positive;
344       Through : Natural);
345
346    function Trim
347      (Source : Unbounded_Wide_Wide_String;
348       Side   : Trim_End) return Unbounded_Wide_Wide_String;
349
350    procedure Trim
351      (Source : in out Unbounded_Wide_Wide_String;
352       Side   : Trim_End);
353
354    function Trim
355      (Source : Unbounded_Wide_Wide_String;
356       Left   : Wide_Wide_Maps.Wide_Wide_Character_Set;
357       Right  : Wide_Wide_Maps.Wide_Wide_Character_Set)
358       return Unbounded_Wide_Wide_String;
359
360    procedure Trim
361      (Source : in out Unbounded_Wide_Wide_String;
362       Left   : Wide_Wide_Maps.Wide_Wide_Character_Set;
363       Right  : Wide_Wide_Maps.Wide_Wide_Character_Set);
364
365    function Head
366      (Source : Unbounded_Wide_Wide_String;
367       Count  : Natural;
368       Pad    : Wide_Wide_Character := Wide_Wide_Space)
369       return Unbounded_Wide_Wide_String;
370
371    procedure Head
372      (Source : in out Unbounded_Wide_Wide_String;
373       Count  : Natural;
374       Pad    : Wide_Wide_Character := Wide_Wide_Space);
375
376    function Tail
377      (Source : Unbounded_Wide_Wide_String;
378       Count  : Natural;
379       Pad    : Wide_Wide_Character := Wide_Wide_Space)
380       return Unbounded_Wide_Wide_String;
381
382    procedure Tail
383      (Source : in out Unbounded_Wide_Wide_String;
384       Count  : Natural;
385       Pad    : Wide_Wide_Character := Wide_Wide_Space);
386
387    function "*"
388      (Left  : Natural;
389       Right : Wide_Wide_Character) return Unbounded_Wide_Wide_String;
390
391    function "*"
392      (Left  : Natural;
393       Right : Wide_Wide_String) return Unbounded_Wide_Wide_String;
394
395    function "*"
396      (Left  : Natural;
397       Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String;
398
399 private
400    pragma Inline (Length);
401
402    package AF renames Ada.Finalization;
403
404    Null_Wide_Wide_String : aliased Wide_Wide_String := "";
405
406    function To_Unbounded_Wide
407      (S : Wide_Wide_String) return Unbounded_Wide_Wide_String
408      renames To_Unbounded_Wide_Wide_String;
409
410    type Unbounded_Wide_Wide_String is new AF.Controlled with record
411       Reference : Wide_Wide_String_Access := Null_Wide_Wide_String'Access;
412       Last      : Natural            := 0;
413    end record;
414
415    --  The Unbounded_Wide_Wide_String is using a buffered implementation to
416    --  increase speed of the Append/Delete/Insert procedures. The Reference
417    --  string pointer above contains the current string value and extra room
418    --  at the end to be used by the next Append routine. Last is the index of
419    --  the string ending character. So the current string value is really
420    --  Reference (1 .. Last).
421
422    pragma Stream_Convert
423      (Unbounded_Wide_Wide_String, To_Unbounded_Wide, To_Wide_Wide_String);
424
425    pragma Finalize_Storage_Only (Unbounded_Wide_Wide_String);
426    --  Finalization is required only for freeing storage
427
428    procedure Initialize (Object : in out Unbounded_Wide_Wide_String);
429    procedure Adjust     (Object : in out Unbounded_Wide_Wide_String);
430    procedure Finalize   (Object : in out Unbounded_Wide_Wide_String);
431    procedure Realloc_For_Chunk
432      (Source     : in out Unbounded_Wide_Wide_String;
433       Chunk_Size : Natural);
434    --  Adjust the size allocated for the string. Add at least Chunk_Size so it
435    --  is safe to add a string of this size at the end of the current content.
436    --  The real size allocated for the string is Chunk_Size + x of the current
437    --  string size. This buffered handling makes the Append unbounded string
438    --  routines very fast.
439
440    Null_Unbounded_Wide_Wide_String : constant Unbounded_Wide_Wide_String :=
441                                        (AF.Controlled with
442                                           Reference =>
443                                             Null_Wide_Wide_String'Access,
444                                           Last => 0);
445 end Ada.Strings.Wide_Wide_Unbounded;