* config/sh/sh.c (sh_gimplify_va_arg_expr): Don't call
[official-gcc.git] / gcc / ada / a-stzunb.adb
blob82dae6f88b74e8358c1d233bf855a846a506dbb0
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 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Ada.Strings.Wide_Wide_Fixed;
33 with Ada.Strings.Wide_Wide_Search;
34 with Ada.Unchecked_Deallocation;
36 package body Ada.Strings.Wide_Wide_Unbounded is
38 use Ada.Finalization;
40 ---------
41 -- "&" --
42 ---------
44 function "&"
45 (Left : Unbounded_Wide_Wide_String;
46 Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String
48 L_Length : constant Natural := Left.Last;
49 R_Length : constant Natural := Right.Last;
50 Result : Unbounded_Wide_Wide_String;
52 begin
53 Result.Last := L_Length + R_Length;
55 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
57 Result.Reference (1 .. L_Length) :=
58 Left.Reference (1 .. Left.Last);
59 Result.Reference (L_Length + 1 .. Result.Last) :=
60 Right.Reference (1 .. Right.Last);
62 return Result;
63 end "&";
65 function "&"
66 (Left : Unbounded_Wide_Wide_String;
67 Right : Wide_Wide_String) return Unbounded_Wide_Wide_String
69 L_Length : constant Natural := Left.Last;
70 Result : Unbounded_Wide_Wide_String;
72 begin
73 Result.Last := L_Length + Right'Length;
75 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
77 Result.Reference (1 .. L_Length) := Left.Reference (1 .. Left.Last);
78 Result.Reference (L_Length + 1 .. Result.Last) := Right;
80 return Result;
81 end "&";
83 function "&"
84 (Left : Wide_Wide_String;
85 Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String
87 R_Length : constant Natural := Right.Last;
88 Result : Unbounded_Wide_Wide_String;
90 begin
91 Result.Last := Left'Length + R_Length;
93 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
95 Result.Reference (1 .. Left'Length) := Left;
96 Result.Reference (Left'Length + 1 .. Result.Last) :=
97 Right.Reference (1 .. Right.Last);
99 return Result;
100 end "&";
102 function "&"
103 (Left : Unbounded_Wide_Wide_String;
104 Right : Wide_Wide_Character) return Unbounded_Wide_Wide_String
106 Result : Unbounded_Wide_Wide_String;
108 begin
109 Result.Last := Left.Last + 1;
111 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
113 Result.Reference (1 .. Result.Last - 1) :=
114 Left.Reference (1 .. Left.Last);
115 Result.Reference (Result.Last) := Right;
117 return Result;
118 end "&";
120 function "&"
121 (Left : Wide_Wide_Character;
122 Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String
124 Result : Unbounded_Wide_Wide_String;
126 begin
127 Result.Last := Right.Last + 1;
129 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
130 Result.Reference (1) := Left;
131 Result.Reference (2 .. Result.Last) :=
132 Right.Reference (1 .. Right.Last);
133 return Result;
134 end "&";
136 ---------
137 -- "*" --
138 ---------
140 function "*"
141 (Left : Natural;
142 Right : Wide_Wide_Character) return Unbounded_Wide_Wide_String
144 Result : Unbounded_Wide_Wide_String;
146 begin
147 Result.Last := Left;
149 Result.Reference := new Wide_Wide_String (1 .. Left);
150 for J in Result.Reference'Range loop
151 Result.Reference (J) := Right;
152 end loop;
154 return Result;
155 end "*";
157 function "*"
158 (Left : Natural;
159 Right : Wide_Wide_String) return Unbounded_Wide_Wide_String
161 Len : constant Natural := Right'Length;
162 K : Positive;
163 Result : Unbounded_Wide_Wide_String;
165 begin
166 Result.Last := Left * Len;
168 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
170 K := 1;
171 for J in 1 .. Left loop
172 Result.Reference (K .. K + Len - 1) := Right;
173 K := K + Len;
174 end loop;
176 return Result;
177 end "*";
179 function "*"
180 (Left : Natural;
181 Right : Unbounded_Wide_Wide_String) return Unbounded_Wide_Wide_String
183 Len : constant Natural := Right.Last;
184 K : Positive;
185 Result : Unbounded_Wide_Wide_String;
187 begin
188 Result.Last := Left * Len;
190 Result.Reference := new Wide_Wide_String (1 .. Result.Last);
192 K := 1;
193 for J in 1 .. Left loop
194 Result.Reference (K .. K + Len - 1) :=
195 Right.Reference (1 .. Right.Last);
196 K := K + Len;
197 end loop;
199 return Result;
200 end "*";
202 ---------
203 -- "<" --
204 ---------
206 function "<"
207 (Left : Unbounded_Wide_Wide_String;
208 Right : Unbounded_Wide_Wide_String) return Boolean
210 begin
211 return
212 Left.Reference (1 .. Left.Last) < Right.Reference (1 .. Right.Last);
213 end "<";
215 function "<"
216 (Left : Unbounded_Wide_Wide_String;
217 Right : Wide_Wide_String) return Boolean
219 begin
220 return Left.Reference (1 .. Left.Last) < Right;
221 end "<";
223 function "<"
224 (Left : Wide_Wide_String;
225 Right : Unbounded_Wide_Wide_String) return Boolean
227 begin
228 return Left < Right.Reference (1 .. Right.Last);
229 end "<";
231 ----------
232 -- "<=" --
233 ----------
235 function "<="
236 (Left : Unbounded_Wide_Wide_String;
237 Right : Unbounded_Wide_Wide_String) return Boolean
239 begin
240 return
241 Left.Reference (1 .. Left.Last) <= Right.Reference (1 .. Right.Last);
242 end "<=";
244 function "<="
245 (Left : Unbounded_Wide_Wide_String;
246 Right : Wide_Wide_String) return Boolean
248 begin
249 return Left.Reference (1 .. Left.Last) <= Right;
250 end "<=";
252 function "<="
253 (Left : Wide_Wide_String;
254 Right : Unbounded_Wide_Wide_String) return Boolean
256 begin
257 return Left <= Right.Reference (1 .. Right.Last);
258 end "<=";
260 ---------
261 -- "=" --
262 ---------
264 function "="
265 (Left : Unbounded_Wide_Wide_String;
266 Right : Unbounded_Wide_Wide_String) return Boolean
268 begin
269 return
270 Left.Reference (1 .. Left.Last) = Right.Reference (1 .. Right.Last);
271 end "=";
273 function "="
274 (Left : Unbounded_Wide_Wide_String;
275 Right : Wide_Wide_String) return Boolean
277 begin
278 return Left.Reference (1 .. Left.Last) = Right;
279 end "=";
281 function "="
282 (Left : Wide_Wide_String;
283 Right : Unbounded_Wide_Wide_String) return Boolean
285 begin
286 return Left = Right.Reference (1 .. Right.Last);
287 end "=";
289 ---------
290 -- ">" --
291 ---------
293 function ">"
294 (Left : Unbounded_Wide_Wide_String;
295 Right : Unbounded_Wide_Wide_String) return Boolean
297 begin
298 return
299 Left.Reference (1 .. Left.Last) > Right.Reference (1 .. Right.Last);
300 end ">";
302 function ">"
303 (Left : Unbounded_Wide_Wide_String;
304 Right : Wide_Wide_String) return Boolean
306 begin
307 return Left.Reference (1 .. Left.Last) > Right;
308 end ">";
310 function ">"
311 (Left : Wide_Wide_String;
312 Right : Unbounded_Wide_Wide_String) return Boolean
314 begin
315 return Left > Right.Reference (1 .. Right.Last);
316 end ">";
318 ----------
319 -- ">=" --
320 ----------
322 function ">="
323 (Left : Unbounded_Wide_Wide_String;
324 Right : Unbounded_Wide_Wide_String) return Boolean
326 begin
327 return
328 Left.Reference (1 .. Left.Last) >= Right.Reference (1 .. Right.Last);
329 end ">=";
331 function ">="
332 (Left : Unbounded_Wide_Wide_String;
333 Right : Wide_Wide_String) return Boolean
335 begin
336 return Left.Reference (1 .. Left.Last) >= Right;
337 end ">=";
339 function ">="
340 (Left : Wide_Wide_String;
341 Right : Unbounded_Wide_Wide_String) return Boolean
343 begin
344 return Left >= Right.Reference (1 .. Right.Last);
345 end ">=";
347 ------------
348 -- Adjust --
349 ------------
351 procedure Adjust (Object : in out Unbounded_Wide_Wide_String) is
352 begin
353 -- Copy string, except we do not copy the statically allocated null
354 -- string, since it can never be deallocated. Note that we do not copy
355 -- extra string room here to avoid dragging unused allocated memory.
357 if Object.Reference /= Null_Wide_Wide_String'Access then
358 Object.Reference :=
359 new Wide_Wide_String'(Object.Reference (1 .. Object.Last));
360 end if;
361 end Adjust;
363 ------------
364 -- Append --
365 ------------
367 procedure Append
368 (Source : in out Unbounded_Wide_Wide_String;
369 New_Item : Unbounded_Wide_Wide_String)
371 begin
372 Realloc_For_Chunk (Source, New_Item.Last);
373 Source.Reference (Source.Last + 1 .. Source.Last + New_Item.Last) :=
374 New_Item.Reference (1 .. New_Item.Last);
375 Source.Last := Source.Last + New_Item.Last;
376 end Append;
378 procedure Append
379 (Source : in out Unbounded_Wide_Wide_String;
380 New_Item : Wide_Wide_String)
382 begin
383 Realloc_For_Chunk (Source, New_Item'Length);
384 Source.Reference (Source.Last + 1 .. Source.Last + New_Item'Length) :=
385 New_Item;
386 Source.Last := Source.Last + New_Item'Length;
387 end Append;
389 procedure Append
390 (Source : in out Unbounded_Wide_Wide_String;
391 New_Item : Wide_Wide_Character)
393 begin
394 Realloc_For_Chunk (Source, 1);
395 Source.Reference (Source.Last + 1) := New_Item;
396 Source.Last := Source.Last + 1;
397 end Append;
399 -----------
400 -- Count --
401 -----------
403 function Count
404 (Source : Unbounded_Wide_Wide_String;
405 Pattern : Wide_Wide_String;
406 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
407 Wide_Wide_Maps.Identity)
408 return Natural
410 begin
411 return
412 Wide_Wide_Search.Count
413 (Source.Reference (1 .. Source.Last), Pattern, Mapping);
414 end Count;
416 function Count
417 (Source : Unbounded_Wide_Wide_String;
418 Pattern : Wide_Wide_String;
419 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
420 return Natural
422 begin
423 return
424 Wide_Wide_Search.Count
425 (Source.Reference (1 .. Source.Last), Pattern, Mapping);
426 end Count;
428 function Count
429 (Source : Unbounded_Wide_Wide_String;
430 Set : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural
432 begin
433 return
434 Wide_Wide_Search.Count
435 (Source.Reference (1 .. Source.Last), Set);
436 end Count;
438 ------------
439 -- Delete --
440 ------------
442 function Delete
443 (Source : Unbounded_Wide_Wide_String;
444 From : Positive;
445 Through : Natural) return Unbounded_Wide_Wide_String
447 begin
448 return
449 To_Unbounded_Wide_Wide_String
450 (Wide_Wide_Fixed.Delete
451 (Source.Reference (1 .. Source.Last), From, Through));
452 end Delete;
454 procedure Delete
455 (Source : in out Unbounded_Wide_Wide_String;
456 From : Positive;
457 Through : Natural)
459 begin
460 if From > Through then
461 null;
463 elsif From < Source.Reference'First or else Through > Source.Last then
464 raise Index_Error;
466 else
467 declare
468 Len : constant Natural := Through - From + 1;
470 begin
471 Source.Reference (From .. Source.Last - Len) :=
472 Source.Reference (Through + 1 .. Source.Last);
473 Source.Last := Source.Last - Len;
474 end;
475 end if;
476 end Delete;
478 -------------
479 -- Element --
480 -------------
482 function Element
483 (Source : Unbounded_Wide_Wide_String;
484 Index : Positive) return Wide_Wide_Character
486 begin
487 if Index <= Source.Last then
488 return Source.Reference (Index);
489 else
490 raise Strings.Index_Error;
491 end if;
492 end Element;
494 --------------
495 -- Finalize --
496 --------------
498 procedure Finalize (Object : in out Unbounded_Wide_Wide_String) is
499 procedure Deallocate is
500 new Ada.Unchecked_Deallocation
501 (Wide_Wide_String, Wide_Wide_String_Access);
503 begin
504 -- Note: Don't try to free statically allocated null string
506 if Object.Reference /= Null_Wide_Wide_String'Access then
507 Deallocate (Object.Reference);
508 Object.Reference := Null_Unbounded_Wide_Wide_String.Reference;
509 Object.Last := 0;
510 end if;
511 end Finalize;
513 ----------------
514 -- Find_Token --
515 ----------------
517 procedure Find_Token
518 (Source : Unbounded_Wide_Wide_String;
519 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
520 From : Positive;
521 Test : Strings.Membership;
522 First : out Positive;
523 Last : out Natural)
525 begin
526 Wide_Wide_Search.Find_Token
527 (Source.Reference (From .. Source.Last), Set, Test, First, Last);
528 end Find_Token;
530 procedure Find_Token
531 (Source : Unbounded_Wide_Wide_String;
532 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
533 Test : Strings.Membership;
534 First : out Positive;
535 Last : out Natural)
537 begin
538 Wide_Wide_Search.Find_Token
539 (Source.Reference (1 .. Source.Last), Set, Test, First, Last);
540 end Find_Token;
542 ----------
543 -- Free --
544 ----------
546 procedure Free (X : in out Wide_Wide_String_Access) is
547 procedure Deallocate is
548 new Ada.Unchecked_Deallocation
549 (Wide_Wide_String, Wide_Wide_String_Access);
551 begin
552 -- Note: Do not try to free statically allocated null string
554 if X /= Null_Unbounded_Wide_Wide_String.Reference then
555 Deallocate (X);
556 end if;
557 end Free;
559 ----------
560 -- Head --
561 ----------
563 function Head
564 (Source : Unbounded_Wide_Wide_String;
565 Count : Natural;
566 Pad : Wide_Wide_Character := Wide_Wide_Space)
567 return Unbounded_Wide_Wide_String
569 begin
570 return To_Unbounded_Wide_Wide_String
571 (Wide_Wide_Fixed.Head
572 (Source.Reference (1 .. Source.Last), Count, Pad));
573 end Head;
575 procedure Head
576 (Source : in out Unbounded_Wide_Wide_String;
577 Count : Natural;
578 Pad : Wide_Wide_Character := Wide_Wide_Space)
580 Old : Wide_Wide_String_Access := Source.Reference;
581 begin
582 Source.Reference :=
583 new Wide_Wide_String'
584 (Wide_Wide_Fixed.Head
585 (Source.Reference (1 .. Source.Last), Count, Pad));
586 Source.Last := Source.Reference'Length;
587 Free (Old);
588 end Head;
590 -----------
591 -- Index --
592 -----------
594 function Index
595 (Source : Unbounded_Wide_Wide_String;
596 Pattern : Wide_Wide_String;
597 Going : Strings.Direction := Strings.Forward;
598 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
599 Wide_Wide_Maps.Identity)
600 return Natural
602 begin
603 return
604 Wide_Wide_Search.Index
605 (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping);
606 end Index;
608 function Index
609 (Source : Unbounded_Wide_Wide_String;
610 Pattern : Wide_Wide_String;
611 Going : Direction := Forward;
612 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
613 return Natural
615 begin
616 return
617 Wide_Wide_Search.Index
618 (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping);
619 end Index;
621 function Index
622 (Source : Unbounded_Wide_Wide_String;
623 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
624 Test : Strings.Membership := Strings.Inside;
625 Going : Strings.Direction := Strings.Forward) return Natural
627 begin
628 return Wide_Wide_Search.Index
629 (Source.Reference (1 .. Source.Last), Set, Test, Going);
630 end Index;
632 function Index
633 (Source : Unbounded_Wide_Wide_String;
634 Pattern : Wide_Wide_String;
635 From : Positive;
636 Going : Direction := Forward;
637 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
638 Wide_Wide_Maps.Identity)
639 return Natural
641 begin
642 return
643 Wide_Wide_Search.Index
644 (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping);
645 end Index;
647 function Index
648 (Source : Unbounded_Wide_Wide_String;
649 Pattern : Wide_Wide_String;
650 From : Positive;
651 Going : Direction := Forward;
652 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
653 return Natural
655 begin
656 return
657 Wide_Wide_Search.Index
658 (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping);
659 end Index;
661 function Index
662 (Source : Unbounded_Wide_Wide_String;
663 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
664 From : Positive;
665 Test : Membership := Inside;
666 Going : Direction := Forward) return Natural
668 begin
669 return
670 Wide_Wide_Search.Index
671 (Source.Reference (1 .. Source.Last), Set, From, Test, Going);
672 end Index;
674 function Index_Non_Blank
675 (Source : Unbounded_Wide_Wide_String;
676 Going : Strings.Direction := Strings.Forward) return Natural
678 begin
679 return
680 Wide_Wide_Search.Index_Non_Blank
681 (Source.Reference (1 .. Source.Last), Going);
682 end Index_Non_Blank;
684 function Index_Non_Blank
685 (Source : Unbounded_Wide_Wide_String;
686 From : Positive;
687 Going : Direction := Forward) return Natural
689 begin
690 return
691 Wide_Wide_Search.Index_Non_Blank
692 (Source.Reference (1 .. Source.Last), From, Going);
693 end Index_Non_Blank;
695 ----------------
696 -- Initialize --
697 ----------------
699 procedure Initialize (Object : in out Unbounded_Wide_Wide_String) is
700 begin
701 Object.Reference := Null_Unbounded_Wide_Wide_String.Reference;
702 Object.Last := 0;
703 end Initialize;
705 ------------
706 -- Insert --
707 ------------
709 function Insert
710 (Source : Unbounded_Wide_Wide_String;
711 Before : Positive;
712 New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String
714 begin
715 return
716 To_Unbounded_Wide_Wide_String
717 (Wide_Wide_Fixed.Insert
718 (Source.Reference (1 .. Source.Last), Before, New_Item));
719 end Insert;
721 procedure Insert
722 (Source : in out Unbounded_Wide_Wide_String;
723 Before : Positive;
724 New_Item : Wide_Wide_String)
726 begin
727 if Before not in Source.Reference'First .. Source.Last + 1 then
728 raise Index_Error;
729 end if;
731 Realloc_For_Chunk (Source, New_Item'Length);
733 Source.Reference
734 (Before + New_Item'Length .. Source.Last + New_Item'Length) :=
735 Source.Reference (Before .. Source.Last);
737 Source.Reference (Before .. Before + New_Item'Length - 1) := New_Item;
738 Source.Last := Source.Last + New_Item'Length;
739 end Insert;
741 ------------
742 -- Length --
743 ------------
745 function Length (Source : Unbounded_Wide_Wide_String) return Natural is
746 begin
747 return Source.Last;
748 end Length;
750 ---------------
751 -- Overwrite --
752 ---------------
754 function Overwrite
755 (Source : Unbounded_Wide_Wide_String;
756 Position : Positive;
757 New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String
759 begin
760 return
761 To_Unbounded_Wide_Wide_String
762 (Wide_Wide_Fixed.Overwrite
763 (Source.Reference (1 .. Source.Last), Position, New_Item));
764 end Overwrite;
766 procedure Overwrite
767 (Source : in out Unbounded_Wide_Wide_String;
768 Position : Positive;
769 New_Item : Wide_Wide_String)
771 NL : constant Natural := New_Item'Length;
772 begin
773 if Position <= Source.Last - NL + 1 then
774 Source.Reference (Position .. Position + NL - 1) := New_Item;
775 else
776 declare
777 Old : Wide_Wide_String_Access := Source.Reference;
778 begin
779 Source.Reference := new Wide_Wide_String'
780 (Wide_Wide_Fixed.Overwrite
781 (Source.Reference (1 .. Source.Last), Position, New_Item));
782 Source.Last := Source.Reference'Length;
783 Free (Old);
784 end;
785 end if;
786 end Overwrite;
788 -----------------------
789 -- Realloc_For_Chunk --
790 -----------------------
792 procedure Realloc_For_Chunk
793 (Source : in out Unbounded_Wide_Wide_String;
794 Chunk_Size : Natural)
796 Growth_Factor : constant := 32;
797 -- The growth factor controls how much extra space is allocated when
798 -- we have to increase the size of an allocated unbounded string. By
799 -- allocating extra space, we avoid the need to reallocate on every
800 -- append, particularly important when a string is built up by repeated
801 -- append operations of small pieces. This is expressed as a factor so
802 -- 32 means add 1/32 of the length of the string as growth space.
804 Min_Mul_Alloc : constant := Standard'Maximum_Alignment;
805 -- Allocation will be done by a multiple of Min_Mul_Alloc This causes
806 -- no memory loss as most (all?) malloc implementations are obliged to
807 -- align the returned memory on the maximum alignment as malloc does not
808 -- know the target alignment.
810 S_Length : constant Natural := Source.Reference'Length;
812 begin
813 if Chunk_Size > S_Length - Source.Last then
814 declare
815 New_Size : constant Positive :=
816 S_Length + Chunk_Size + (S_Length / Growth_Factor);
818 New_Rounded_Up_Size : constant Positive :=
819 ((New_Size - 1) / Min_Mul_Alloc + 1) *
820 Min_Mul_Alloc;
822 Tmp : constant Wide_Wide_String_Access :=
823 new Wide_Wide_String (1 .. New_Rounded_Up_Size);
825 begin
826 Tmp (1 .. Source.Last) := Source.Reference (1 .. Source.Last);
827 Free (Source.Reference);
828 Source.Reference := Tmp;
829 end;
830 end if;
831 end Realloc_For_Chunk;
833 ---------------------
834 -- Replace_Element --
835 ---------------------
837 procedure Replace_Element
838 (Source : in out Unbounded_Wide_Wide_String;
839 Index : Positive;
840 By : Wide_Wide_Character)
842 begin
843 if Index <= Source.Last then
844 Source.Reference (Index) := By;
845 else
846 raise Strings.Index_Error;
847 end if;
848 end Replace_Element;
850 -------------------
851 -- Replace_Slice --
852 -------------------
854 function Replace_Slice
855 (Source : Unbounded_Wide_Wide_String;
856 Low : Positive;
857 High : Natural;
858 By : Wide_Wide_String) return Unbounded_Wide_Wide_String
860 begin
861 return To_Unbounded_Wide_Wide_String
862 (Wide_Wide_Fixed.Replace_Slice
863 (Source.Reference (1 .. Source.Last), Low, High, By));
864 end Replace_Slice;
866 procedure Replace_Slice
867 (Source : in out Unbounded_Wide_Wide_String;
868 Low : Positive;
869 High : Natural;
870 By : Wide_Wide_String)
872 Old : Wide_Wide_String_Access := Source.Reference;
873 begin
874 Source.Reference := new Wide_Wide_String'
875 (Wide_Wide_Fixed.Replace_Slice
876 (Source.Reference (1 .. Source.Last), Low, High, By));
877 Source.Last := Source.Reference'Length;
878 Free (Old);
879 end Replace_Slice;
881 ------------------------------------
882 -- Set_Unbounded_Wide_Wide_String --
883 ------------------------------------
885 procedure Set_Unbounded_Wide_Wide_String
886 (Target : out Unbounded_Wide_Wide_String;
887 Source : Wide_Wide_String)
889 begin
890 Target.Last := Source'Length;
891 Target.Reference := new Wide_Wide_String (1 .. Source'Length);
892 Target.Reference.all := Source;
893 end Set_Unbounded_Wide_Wide_String;
895 -----------
896 -- Slice --
897 -----------
899 function Slice
900 (Source : Unbounded_Wide_Wide_String;
901 Low : Positive;
902 High : Natural) return Wide_Wide_String
904 begin
905 -- Note: test of High > Length is in accordance with AI95-00128
907 if Low > Source.Last + 1 or else High > Source.Last then
908 raise Index_Error;
909 else
910 return Source.Reference (Low .. High);
911 end if;
912 end Slice;
914 ----------
915 -- Tail --
916 ----------
918 function Tail
919 (Source : Unbounded_Wide_Wide_String;
920 Count : Natural;
921 Pad : Wide_Wide_Character := Wide_Wide_Space)
922 return Unbounded_Wide_Wide_String is
923 begin
924 return To_Unbounded_Wide_Wide_String
925 (Wide_Wide_Fixed.Tail
926 (Source.Reference (1 .. Source.Last), Count, Pad));
927 end Tail;
929 procedure Tail
930 (Source : in out Unbounded_Wide_Wide_String;
931 Count : Natural;
932 Pad : Wide_Wide_Character := Wide_Wide_Space)
934 Old : Wide_Wide_String_Access := Source.Reference;
935 begin
936 Source.Reference := new Wide_Wide_String'
937 (Wide_Wide_Fixed.Tail
938 (Source.Reference (1 .. Source.Last), Count, Pad));
939 Source.Last := Source.Reference'Length;
940 Free (Old);
941 end Tail;
943 -----------------------------------
944 -- To_Unbounded_Wide_Wide_String --
945 -----------------------------------
947 function To_Unbounded_Wide_Wide_String
948 (Source : Wide_Wide_String) return Unbounded_Wide_Wide_String
950 Result : Unbounded_Wide_Wide_String;
951 begin
952 Result.Last := Source'Length;
953 Result.Reference := new Wide_Wide_String (1 .. Source'Length);
954 Result.Reference.all := Source;
955 return Result;
956 end To_Unbounded_Wide_Wide_String;
958 function To_Unbounded_Wide_Wide_String
959 (Length : Natural) return Unbounded_Wide_Wide_String
961 Result : Unbounded_Wide_Wide_String;
962 begin
963 Result.Last := Length;
964 Result.Reference := new Wide_Wide_String (1 .. Length);
965 return Result;
966 end To_Unbounded_Wide_Wide_String;
968 -------------------------
969 -- To_Wide_Wide_String --
970 -------------------------
972 function To_Wide_Wide_String
973 (Source : Unbounded_Wide_Wide_String) return Wide_Wide_String
975 begin
976 return Source.Reference (1 .. Source.Last);
977 end To_Wide_Wide_String;
979 ---------------
980 -- Translate --
981 ---------------
983 function Translate
984 (Source : Unbounded_Wide_Wide_String;
985 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
986 return Unbounded_Wide_Wide_String
988 begin
989 return
990 To_Unbounded_Wide_Wide_String
991 (Wide_Wide_Fixed.Translate
992 (Source.Reference (1 .. Source.Last), Mapping));
993 end Translate;
995 procedure Translate
996 (Source : in out Unbounded_Wide_Wide_String;
997 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
999 begin
1000 Wide_Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping);
1001 end Translate;
1003 function Translate
1004 (Source : Unbounded_Wide_Wide_String;
1005 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
1006 return Unbounded_Wide_Wide_String
1008 begin
1009 return
1010 To_Unbounded_Wide_Wide_String
1011 (Wide_Wide_Fixed.Translate
1012 (Source.Reference (1 .. Source.Last), Mapping));
1013 end Translate;
1015 procedure Translate
1016 (Source : in out Unbounded_Wide_Wide_String;
1017 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
1019 begin
1020 Wide_Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping);
1021 end Translate;
1023 ----------
1024 -- Trim --
1025 ----------
1027 function Trim
1028 (Source : Unbounded_Wide_Wide_String;
1029 Side : Trim_End) return Unbounded_Wide_Wide_String
1031 begin
1032 return
1033 To_Unbounded_Wide_Wide_String
1034 (Wide_Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side));
1035 end Trim;
1037 procedure Trim
1038 (Source : in out Unbounded_Wide_Wide_String;
1039 Side : Trim_End)
1041 Old : Wide_Wide_String_Access := Source.Reference;
1042 begin
1043 Source.Reference :=
1044 new Wide_Wide_String'
1045 (Wide_Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side));
1046 Source.Last := Source.Reference'Length;
1047 Free (Old);
1048 end Trim;
1050 function Trim
1051 (Source : Unbounded_Wide_Wide_String;
1052 Left : Wide_Wide_Maps.Wide_Wide_Character_Set;
1053 Right : Wide_Wide_Maps.Wide_Wide_Character_Set)
1054 return Unbounded_Wide_Wide_String
1056 begin
1057 return
1058 To_Unbounded_Wide_Wide_String
1059 (Wide_Wide_Fixed.Trim
1060 (Source.Reference (1 .. Source.Last), Left, Right));
1061 end Trim;
1063 procedure Trim
1064 (Source : in out Unbounded_Wide_Wide_String;
1065 Left : Wide_Wide_Maps.Wide_Wide_Character_Set;
1066 Right : Wide_Wide_Maps.Wide_Wide_Character_Set)
1068 Old : Wide_Wide_String_Access := Source.Reference;
1069 begin
1070 Source.Reference :=
1071 new Wide_Wide_String'
1072 (Wide_Wide_Fixed.Trim
1073 (Source.Reference (1 .. Source.Last), Left, Right));
1074 Source.Last := Source.Reference'Length;
1075 Free (Old);
1076 end Trim;
1078 ---------------------
1079 -- Unbounded_Slice --
1080 ---------------------
1082 function Unbounded_Slice
1083 (Source : Unbounded_Wide_Wide_String;
1084 Low : Positive;
1085 High : Natural) return Unbounded_Wide_Wide_String
1087 begin
1088 if Low > Source.Last + 1 or else High > Source.Last then
1089 raise Index_Error;
1090 else
1091 return
1092 To_Unbounded_Wide_Wide_String (Source.Reference.all (Low .. High));
1093 end if;
1094 end Unbounded_Slice;
1096 procedure Unbounded_Slice
1097 (Source : Unbounded_Wide_Wide_String;
1098 Target : out Unbounded_Wide_Wide_String;
1099 Low : Positive;
1100 High : Natural)
1102 begin
1103 if Low > Source.Last + 1 or else High > Source.Last then
1104 raise Index_Error;
1105 else
1106 Target :=
1107 To_Unbounded_Wide_Wide_String (Source.Reference.all (Low .. High));
1108 end if;
1109 end Unbounded_Slice;
1111 end Ada.Strings.Wide_Wide_Unbounded;