Debian Codegraph @

gcc/ada/libgnat/a-stwiun__shared.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R I N G S . W I D E _ U N B O U N D E D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2025, 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 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. --
21 -- --
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. --
25 -- --
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/>. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 -- --
34 ------------------------------------------------------------------------------
35
36 -- This version is supported on:
37 -- - all Alpha platforms
38 -- - all ia64 platforms
39 -- - all PowerPC platforms
40 -- - all SPARC V9 platforms
41 -- - all x86 platforms
42 -- - all x86_64 platforms
43
44 with Ada.Strings.Wide_Maps;
45 private with Ada.Finalization;
46 private with System.Atomic_Counters;
47
48 package Ada.Strings.Wide_Unbounded is
49 pragma Preelaborate;
50
51 type Unbounded_Wide_String is private;
52 pragma Preelaborable_Initialization (Unbounded_Wide_String);
53
54 Null_Unbounded_Wide_String : constant Unbounded_Wide_String;
55
56 function Length (Source : Unbounded_Wide_String) return Natural;
57
58 type Wide_String_Access is access all Wide_String;
59
60 procedure Free (X : in out Wide_String_Access);
61
62 --------------------------------------------------------
63 -- Conversion, Concatenation, and Selection Functions --
64 --------------------------------------------------------
65
66 function To_Unbounded_Wide_String
67 (Source : Wide_String) return Unbounded_Wide_String;
68
69 function To_Unbounded_Wide_String
70 (Length : Natural) return Unbounded_Wide_String;
71
72 function To_Wide_String
73 (Source : Unbounded_Wide_String) return Wide_String;
74
75 procedure Set_Unbounded_Wide_String
76 (Target : out Unbounded_Wide_String;
77 Source : Wide_String);
78 pragma Ada_05 (Set_Unbounded_Wide_String);
79
80 procedure Append
81 (Source : in out Unbounded_Wide_String;
82 New_Item : Unbounded_Wide_String)
83 with Inline => True;
84
85 procedure Append
86 (Source : in out Unbounded_Wide_String;
87 New_Item : Wide_String)
88 with Inline => True;
89
90 procedure Append
91 (Source : in out Unbounded_Wide_String;
92 New_Item : Wide_Character)
93 with Inline => True;
94
95 function "&"
96 (Left : Unbounded_Wide_String;
97 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
98
99 function "&"
100 (Left : Unbounded_Wide_String;
101 Right : Wide_String) return Unbounded_Wide_String;
102
103 function "&"
104 (Left : Wide_String;
105 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
106
107 function "&"
108 (Left : Unbounded_Wide_String;
109 Right : Wide_Character) return Unbounded_Wide_String;
110
111 function "&"
112 (Left : Wide_Character;
113 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
114
115 function Element
116 (Source : Unbounded_Wide_String;
117 Index : Positive) return Wide_Character;
118
119 procedure Replace_Element
120 (Source : in out Unbounded_Wide_String;
121 Index : Positive;
122 By : Wide_Character);
123
124 function Slice
125 (Source : Unbounded_Wide_String;
126 Low : Positive;
127 High : Natural) return Wide_String;
128
129 function Unbounded_Slice
130 (Source : Unbounded_Wide_String;
131 Low : Positive;
132 High : Natural) return Unbounded_Wide_String;
133 pragma Ada_05 (Unbounded_Slice);
134
135 procedure Unbounded_Slice
136 (Source : Unbounded_Wide_String;
137 Target : out Unbounded_Wide_String;
138 Low : Positive;
139 High : Natural);
140 pragma Ada_05 (Unbounded_Slice);
141
142 function "="
143 (Left : Unbounded_Wide_String;
144 Right : Unbounded_Wide_String) return Boolean;
145
146 function "="
147 (Left : Unbounded_Wide_String;
148 Right : Wide_String) return Boolean;
149
150 function "="
151 (Left : Wide_String;
152 Right : Unbounded_Wide_String) return Boolean;
153
154 function "<"
155 (Left : Unbounded_Wide_String;
156 Right : Unbounded_Wide_String) return Boolean;
157
158 function "<"
159 (Left : Unbounded_Wide_String;
160 Right : Wide_String) return Boolean;
161
162 function "<"
163 (Left : Wide_String;
164 Right : Unbounded_Wide_String) return Boolean;
165
166 function "<="
167 (Left : Unbounded_Wide_String;
168 Right : Unbounded_Wide_String) return Boolean;
169
170 function "<="
171 (Left : Unbounded_Wide_String;
172 Right : Wide_String) return Boolean;
173
174 function "<="
175 (Left : Wide_String;
176 Right : Unbounded_Wide_String) return Boolean;
177
178 function ">"
179 (Left : Unbounded_Wide_String;
180 Right : Unbounded_Wide_String) return Boolean;
181
182 function ">"
183 (Left : Unbounded_Wide_String;
184 Right : Wide_String) return Boolean;
185
186 function ">"
187 (Left : Wide_String;
188 Right : Unbounded_Wide_String) return Boolean;
189
190 function ">="
191 (Left : Unbounded_Wide_String;
192 Right : Unbounded_Wide_String) return Boolean;
193
194 function ">="
195 (Left : Unbounded_Wide_String;
196 Right : Wide_String) return Boolean;
197
198 function ">="
199 (Left : Wide_String;
200 Right : Unbounded_Wide_String) return Boolean;
201
202 ------------------------
203 -- Search Subprograms --
204 ------------------------
205
206 function Index
207 (Source : Unbounded_Wide_String;
208 Pattern : Wide_String;
209 Going : Direction := Forward;
210 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
211 return Natural;
212
213 function Index
214 (Source : Unbounded_Wide_String;
215 Pattern : Wide_String;
216 Going : Direction := Forward;
217 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
218
219 function Index
220 (Source : Unbounded_Wide_String;
221 Set : Wide_Maps.Wide_Character_Set;
222 Test : Membership := Inside;
223 Going : Direction := Forward) return Natural;
224
225 function Index
226 (Source : Unbounded_Wide_String;
227 Pattern : Wide_String;
228 From : Positive;
229 Going : Direction := Forward;
230 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
231 return Natural;
232 pragma Ada_05 (Index);
233
234 function Index
235 (Source : Unbounded_Wide_String;
236 Pattern : Wide_String;
237 From : Positive;
238 Going : Direction := Forward;
239 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
240 pragma Ada_05 (Index);
241
242 function Index
243 (Source : Unbounded_Wide_String;
244 Set : Wide_Maps.Wide_Character_Set;
245 From : Positive;
246 Test : Membership := Inside;
247 Going : Direction := Forward) return Natural;
248 pragma Ada_05 (Index);
249
250 function Index_Non_Blank
251 (Source : Unbounded_Wide_String;
252 Going : Direction := Forward) return Natural;
253
254 function Index_Non_Blank
255 (Source : Unbounded_Wide_String;
256 From : Positive;
257 Going : Direction := Forward) return Natural;
258 pragma Ada_05 (Index_Non_Blank);
259
260 function Count
261 (Source : Unbounded_Wide_String;
262 Pattern : Wide_String;
263 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
264 return Natural;
265
266 function Count
267 (Source : Unbounded_Wide_String;
268 Pattern : Wide_String;
269 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural;
270
271 function Count
272 (Source : Unbounded_Wide_String;
273 Set : Wide_Maps.Wide_Character_Set) return Natural;
274
275 procedure Find_Token
276 (Source : Unbounded_Wide_String;
277 Set : Wide_Maps.Wide_Character_Set;
278 From : Positive;
279 Test : Membership;
280 First : out Positive;
281 Last : out Natural);
282 pragma Ada_2012 (Find_Token);
283
284 procedure Find_Token
285 (Source : Unbounded_Wide_String;
286 Set : Wide_Maps.Wide_Character_Set;
287 Test : Membership;
288 First : out Positive;
289 Last : out Natural);
290
291 ------------------------------------
292 -- String Translation Subprograms --
293 ------------------------------------
294
295 function Translate
296 (Source : Unbounded_Wide_String;
297 Mapping : Wide_Maps.Wide_Character_Mapping)
298 return Unbounded_Wide_String;
299
300 procedure Translate
301 (Source : in out Unbounded_Wide_String;
302 Mapping : Wide_Maps.Wide_Character_Mapping);
303
304 function Translate
305 (Source : Unbounded_Wide_String;
306 Mapping : Wide_Maps.Wide_Character_Mapping_Function)
307 return Unbounded_Wide_String;
308
309 procedure Translate
310 (Source : in out Unbounded_Wide_String;
311 Mapping : Wide_Maps.Wide_Character_Mapping_Function);
312
313 ---------------------------------------
314 -- String Transformation Subprograms --
315 ---------------------------------------
316
317 function Replace_Slice
318 (Source : Unbounded_Wide_String;
319 Low : Positive;
320 High : Natural;
321 By : Wide_String) return Unbounded_Wide_String;
322
323 procedure Replace_Slice
324 (Source : in out Unbounded_Wide_String;
325 Low : Positive;
326 High : Natural;
327 By : Wide_String);
328
329 function Insert
330 (Source : Unbounded_Wide_String;
331 Before : Positive;
332 New_Item : Wide_String) return Unbounded_Wide_String;
333
334 procedure Insert
335 (Source : in out Unbounded_Wide_String;
336 Before : Positive;
337 New_Item : Wide_String);
338
339 function Overwrite
340 (Source : Unbounded_Wide_String;
341 Position : Positive;
342 New_Item : Wide_String) return Unbounded_Wide_String;
343
344 procedure Overwrite
345 (Source : in out Unbounded_Wide_String;
346 Position : Positive;
347 New_Item : Wide_String);
348
349 function Delete
350 (Source : Unbounded_Wide_String;
351 From : Positive;
352 Through : Natural) return Unbounded_Wide_String;
353
354 procedure Delete
355 (Source : in out Unbounded_Wide_String;
356 From : Positive;
357 Through : Natural);
358
359 function Trim
360 (Source : Unbounded_Wide_String;
361 Side : Trim_End) return Unbounded_Wide_String;
362
363 procedure Trim
364 (Source : in out Unbounded_Wide_String;
365 Side : Trim_End);
366
367 function Trim
368 (Source : Unbounded_Wide_String;
369 Left : Wide_Maps.Wide_Character_Set;
370 Right : Wide_Maps.Wide_Character_Set) return Unbounded_Wide_String;
371
372 procedure Trim
373 (Source : in out Unbounded_Wide_String;
374 Left : Wide_Maps.Wide_Character_Set;
375 Right : Wide_Maps.Wide_Character_Set);
376
377 function Head
378 (Source : Unbounded_Wide_String;
379 Count : Natural;
380 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
381
382 procedure Head
383 (Source : in out Unbounded_Wide_String;
384 Count : Natural;
385 Pad : Wide_Character := Wide_Space);
386
387 function Tail
388 (Source : Unbounded_Wide_String;
389 Count : Natural;
390 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String;
391
392 procedure Tail
393 (Source : in out Unbounded_Wide_String;
394 Count : Natural;
395 Pad : Wide_Character := Wide_Space);
396
397 function "*"
398 (Left : Natural;
399 Right : Wide_Character) return Unbounded_Wide_String;
400
401 function "*"
402 (Left : Natural;
403 Right : Wide_String) return Unbounded_Wide_String;
404
405 function "*"
406 (Left : Natural;
407 Right : Unbounded_Wide_String) return Unbounded_Wide_String;
408
409 private
410 pragma Inline (Length);
411
412 package AF renames Ada.Finalization;
413
414 type Shared_Wide_String (Max_Length : Natural) is limited record
415 Counter : System.Atomic_Counters.Atomic_Counter;
416 -- Reference counter
417
418 Last : Natural := 0;
419 Data : Wide_String (1 .. Max_Length);
420 -- Last is the index of last significant element of the Data. All
421 -- elements with larger indexes are just extra room for expansion.
422 end record;
423
424 type Shared_Wide_String_Access is access all Shared_Wide_String;
425
426 procedure Reference (Item : not null Shared_Wide_String_Access);
427 -- Increment reference counter.
428
429 procedure Unreference (Item : not null Shared_Wide_String_Access);
430 -- Decrement reference counter. Deallocate Item when ref counter is zero
431
432 function Can_Be_Reused
433 (Item : Shared_Wide_String_Access;
434 Length : Natural) return Boolean;
435 -- Returns True if Shared_Wide_String can be reused. There are two criteria
436 -- when Shared_Wide_String can be reused: its reference counter must be one
437 -- (thus Shared_Wide_String is owned exclusively) and its size is
438 -- sufficient to store string with specified length effectively.
439
440 function Allocate (Max_Length : Natural) return Shared_Wide_String_Access;
441 -- Allocates new Shared_Wide_String with at least specified maximum length.
442 -- Actual maximum length of the allocated Shared_Wide_String can be
443 -- slightly greater. Returns reference to Empty_Shared_Wide_String when
444 -- requested length is zero.
445
446 Empty_Shared_Wide_String : aliased Shared_Wide_String (0);
447
448 function To_Unbounded (S : Wide_String) return Unbounded_Wide_String
449 renames To_Unbounded_Wide_String;
450 -- This renames are here only to be used in the pragma Stream_Convert
451
452 type Unbounded_Wide_String is new AF.Controlled with record
453 Reference : Shared_Wide_String_Access := Empty_Shared_Wide_String'Access;
454 end record;
455
456 -- The Unbounded_Wide_String uses several techniques to increase speed of
457 -- the application:
458
459 -- - implicit sharing or copy-on-write. Unbounded_Wide_String contains
460 -- only the reference to the data which is shared between several
461 -- instances. The shared data is reallocated only when its value is
462 -- changed and the object mutation can't be used or it is inefficient to
463 -- use it;
464
465 -- - object mutation. Shared data object can be reused without memory
466 -- reallocation when all of the following requirements are meat:
467 -- - shared data object don't used anywhere longer;
468 -- - its size is sufficient to store new value;
469 -- - the gap after reuse is less than some threshold.
470
471 -- - memory preallocation. Most of used memory allocation algorithms
472 -- aligns allocated segment on the some boundary, thus some amount of
473 -- additional memory can be preallocated without any impact. Such
474 -- preallocated memory can used later by Append/Insert operations
475 -- without reallocation.
476
477 -- Reference counting uses GCC builtin atomic operations, which allows safe
478 -- sharing of internal data between Ada tasks. Nevertheless, this does not
479 -- make objects of Unbounded_String thread-safe: an instance cannot be
480 -- accessed by several tasks simultaneously.
481
482 pragma Stream_Convert (Unbounded_Wide_String, To_Unbounded, To_Wide_String);
483 -- Provide stream routines without dragging in Ada.Streams
484
485 pragma Finalize_Storage_Only (Unbounded_Wide_String);
486 -- Finalization is required only for freeing storage
487
488 overriding procedure Initialize (Object : in out Unbounded_Wide_String);
489 overriding procedure Adjust (Object : in out Unbounded_Wide_String);
490 overriding procedure Finalize (Object : in out Unbounded_Wide_String);
491 pragma Inline (Initialize, Adjust);
492
493 Null_Unbounded_Wide_String : constant Unbounded_Wide_String :=
494 (AF.Controlled with
495 Reference =>
496 Empty_Shared_Wide_String'Access);
497
498 end Ada.Strings.Wide_Unbounded;