1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . S T R I N G S . W I D E _ U N B O U N D E D --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
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. --
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 3, 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. --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
34 ------------------------------------------------------------------------------
36 with Ada.Strings.Wide_Maps;
37 with Ada.Finalization;
39 package Ada.Strings.Wide_Unbounded is
42 type Unbounded_Wide_String is private;
43 pragma Preelaborable_Initialization (Unbounded_Wide_String);
45 Null_Unbounded_Wide_String : constant Unbounded_Wide_String;
47 function Length (Source : Unbounded_Wide_String) return Natural;
49 type Wide_String_Access is access all Wide_String;
51 procedure Free (X : in out Wide_String_Access);
53 --------------------------------------------------------
54 -- Conversion, Concatenation, and Selection Functions --
55 --------------------------------------------------------
57 function To_Unbounded_Wide_String
58 (Source : Wide_String) return Unbounded_Wide_String;
60 function To_Unbounded_Wide_String
61 (Length : Natural) return Unbounded_Wide_String;
63 function To_Wide_String
64 (Source : Unbounded_Wide_String)
67 procedure Set_Unbounded_Wide_String
68 (Target : out Unbounded_Wide_String;
69 Source : Wide_String);
70 pragma Ada_05 (Set_Unbounded_Wide_String);
73 (Source : in out Unbounded_Wide_String;
74 New_Item : Unbounded_Wide_String);
77 (Source : in out Unbounded_Wide_String;
78 New_Item : Wide_String);
81 (Source : in out Unbounded_Wide_String;
82 New_Item : Wide_Character);
85 (Left : Unbounded_Wide_String;
86 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
89 (Left : Unbounded_Wide_String;
90 Right : Wide_String) return Unbounded_Wide_String;
94 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
97 (Left : Unbounded_Wide_String;
98 Right : Wide_Character) return Unbounded_Wide_String;
101 (Left : Wide_Character;
102 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
105 (Source : Unbounded_Wide_String;
106 Index : Positive) return Wide_Character;
108 procedure Replace_Element
109 (Source : in out Unbounded_Wide_String;
111 By : Wide_Character);
114 (Source : Unbounded_Wide_String;
116 High : Natural) return Wide_String;
118 function Unbounded_Slice
119 (Source : Unbounded_Wide_String;
121 High : Natural) return Unbounded_Wide_String;
122 pragma Ada_05 (Unbounded_Slice);
124 procedure Unbounded_Slice
125 (Source : Unbounded_Wide_String;
126 Target : out Unbounded_Wide_String;
129 pragma Ada_05 (Unbounded_Slice);
132 (Left : Unbounded_Wide_String;
133 Right : Unbounded_Wide_String) return Boolean;
136 (Left : Unbounded_Wide_String;
137 Right : Wide_String) return Boolean;
141 Right : Unbounded_Wide_String) return Boolean;
144 (Left : Unbounded_Wide_String;
145 Right : Unbounded_Wide_String) return Boolean;
148 (Left : Unbounded_Wide_String;
149 Right : Wide_String) return Boolean;
153 Right : Unbounded_Wide_String) return Boolean;
156 (Left : Unbounded_Wide_String;
157 Right : Unbounded_Wide_String) return Boolean;
160 (Left : Unbounded_Wide_String;
161 Right : Wide_String) return Boolean;
165 Right : Unbounded_Wide_String) return Boolean;
168 (Left : Unbounded_Wide_String;
169 Right : Unbounded_Wide_String) return Boolean;
172 (Left : Unbounded_Wide_String;
173 Right : Wide_String) return Boolean;
177 Right : Unbounded_Wide_String) return Boolean;
180 (Left : Unbounded_Wide_String;
181 Right : Unbounded_Wide_String) return Boolean;
184 (Left : Unbounded_Wide_String;
185 Right : Wide_String) return Boolean;
189 Right : Unbounded_Wide_String) return Boolean;
191 ------------------------
192 -- Search Subprograms --
193 ------------------------
196 (Source : Unbounded_Wide_String;
197 Pattern : Wide_String;
198 Going : Direction := Forward;
199 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
203 (Source : Unbounded_Wide_String;
204 Pattern : Wide_String;
205 Going : Direction := Forward;
206 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
209 (Source : Unbounded_Wide_String;
210 Set : Wide_Maps.Wide_Character_Set;
211 Test : Membership := Inside;
212 Going : Direction := Forward) return Natural;
215 (Source : Unbounded_Wide_String;
216 Pattern : Wide_String;
218 Going : Direction := Forward;
219 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
221 pragma Ada_05 (Index);
224 (Source : Unbounded_Wide_String;
225 Pattern : Wide_String;
227 Going : Direction := Forward;
228 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
229 pragma Ada_05 (Index);
232 (Source : Unbounded_Wide_String;
233 Set : Wide_Maps.Wide_Character_Set;
235 Test : Membership := Inside;
236 Going : Direction := Forward) return Natural;
237 pragma Ada_05 (Index);
239 function Index_Non_Blank
240 (Source : Unbounded_Wide_String;
241 Going : Direction := Forward) return Natural;
243 function Index_Non_Blank
244 (Source : Unbounded_Wide_String;
246 Going : Direction := Forward) return Natural;
247 pragma Ada_05 (Index_Non_Blank);
250 (Source : Unbounded_Wide_String;
251 Pattern : Wide_String;
252 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
256 (Source : Unbounded_Wide_String;
257 Pattern : Wide_String;
258 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
261 (Source : Unbounded_Wide_String;
262 Set : Wide_Maps.Wide_Character_Set) return Natural;
265 (Source : Unbounded_Wide_String;
266 Set : Wide_Maps.Wide_Character_Set;
269 First : out Positive;
271 pragma Ada_2012 (Find_Token);
274 (Source : Unbounded_Wide_String;
275 Set : Wide_Maps.Wide_Character_Set;
277 First : out Positive;
280 ------------------------------------
281 -- String Translation Subprograms --
282 ------------------------------------
285 (Source : Unbounded_Wide_String;
286 Mapping : Wide_Maps.Wide_Character_Mapping)
287 return Unbounded_Wide_String;
290 (Source : in out Unbounded_Wide_String;
291 Mapping : Wide_Maps.Wide_Character_Mapping);
294 (Source : Unbounded_Wide_String;
295 Mapping : Wide_Maps.Wide_Character_Mapping_Function)
296 return Unbounded_Wide_String;
299 (Source : in out Unbounded_Wide_String;
300 Mapping : Wide_Maps.Wide_Character_Mapping_Function);
302 ---------------------------------------
303 -- String Transformation Subprograms --
304 ---------------------------------------
306 function Replace_Slice
307 (Source : Unbounded_Wide_String;
310 By : Wide_String) return Unbounded_Wide_String;
312 procedure Replace_Slice
313 (Source : in out Unbounded_Wide_String;
319 (Source : Unbounded_Wide_String;
321 New_Item : Wide_String) return Unbounded_Wide_String;
324 (Source : in out Unbounded_Wide_String;
326 New_Item : Wide_String);
329 (Source : Unbounded_Wide_String;
331 New_Item : Wide_String) return Unbounded_Wide_String;
334 (Source : in out Unbounded_Wide_String;
336 New_Item : Wide_String);
339 (Source : Unbounded_Wide_String;
341 Through : Natural) return Unbounded_Wide_String;
344 (Source : in out Unbounded_Wide_String;
349 (Source : Unbounded_Wide_String;
350 Side : Trim_End) return Unbounded_Wide_String;
353 (Source : in out Unbounded_Wide_String;
357 (Source : Unbounded_Wide_String;
358 Left : Wide_Maps.Wide_Character_Set;
359 Right : Wide_Maps.Wide_Character_Set) return Unbounded_Wide_String;
362 (Source : in out Unbounded_Wide_String;
363 Left : Wide_Maps.Wide_Character_Set;
364 Right : Wide_Maps.Wide_Character_Set);
367 (Source : Unbounded_Wide_String;
369 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
372 (Source : in out Unbounded_Wide_String;
374 Pad : Wide_Character := Wide_Space);
377 (Source : Unbounded_Wide_String;
379 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
382 (Source : in out Unbounded_Wide_String;
384 Pad : Wide_Character := Wide_Space);
388 Right : Wide_Character) return Unbounded_Wide_String;
392 Right : Wide_String) return Unbounded_Wide_String;
396 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
399 pragma Inline (Length);
401 package AF renames Ada.Finalization;
403 Null_Wide_String : aliased Wide_String := "";
405 function To_Unbounded_Wide (S : Wide_String) return Unbounded_Wide_String
406 renames To_Unbounded_Wide_String;
408 type Unbounded_Wide_String is new AF.Controlled with record
409 Reference : Wide_String_Access := Null_Wide_String'Access;
413 -- The Unbounded_Wide_String is using a buffered implementation to increase
414 -- speed of the Append/Delete/Insert procedures. The Reference string
415 -- pointer above contains the current string value and extra room at the
416 -- end to be used by the next Append routine. Last is the index of the
417 -- string ending character. So the current string value is really
418 -- Reference (1 .. Last).
420 pragma Stream_Convert
421 (Unbounded_Wide_String, To_Unbounded_Wide, To_Wide_String);
423 pragma Finalize_Storage_Only (Unbounded_Wide_String);
424 -- Finalization is required only for freeing storage
426 procedure Initialize (Object : in out Unbounded_Wide_String);
427 procedure Adjust (Object : in out Unbounded_Wide_String);
428 procedure Finalize (Object : in out Unbounded_Wide_String);
430 procedure Realloc_For_Chunk
431 (Source : in out Unbounded_Wide_String;
432 Chunk_Size : Natural);
433 -- Adjust the size allocated for the string. Add at least Chunk_Size so it
434 -- is safe to add a string of this size at the end of the current content.
435 -- The real size allocated for the string is Chunk_Size + x of the current
436 -- string size. This buffered handling makes the Append unbounded string
437 -- routines very fast.
439 Null_Unbounded_Wide_String : constant Unbounded_Wide_String :=
441 Reference => Null_Wide_String'Access,
443 end Ada.Strings.Wide_Unbounded;