sh.c (shift_insns_rtx, [...]): Truncate shift counts to avoid out-of-bounds array...
[official-gcc.git] / gcc / ada / a-stzunb.adb
blob226e26906ed61d7283e354b18b80da4e9e6a2918
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-2009, 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 Test : Strings.Membership;
521 First : out Positive;
522 Last : out Natural)
524 begin
525 Wide_Wide_Search.Find_Token
526 (Source.Reference (1 .. Source.Last), Set, Test, First, Last);
527 end Find_Token;
529 ----------
530 -- Free --
531 ----------
533 procedure Free (X : in out Wide_Wide_String_Access) is
534 procedure Deallocate is
535 new Ada.Unchecked_Deallocation
536 (Wide_Wide_String, Wide_Wide_String_Access);
538 begin
539 -- Note: Do not try to free statically allocated null string
541 if X /= Null_Unbounded_Wide_Wide_String.Reference then
542 Deallocate (X);
543 end if;
544 end Free;
546 ----------
547 -- Head --
548 ----------
550 function Head
551 (Source : Unbounded_Wide_Wide_String;
552 Count : Natural;
553 Pad : Wide_Wide_Character := Wide_Wide_Space)
554 return Unbounded_Wide_Wide_String
556 begin
557 return To_Unbounded_Wide_Wide_String
558 (Wide_Wide_Fixed.Head
559 (Source.Reference (1 .. Source.Last), Count, Pad));
560 end Head;
562 procedure Head
563 (Source : in out Unbounded_Wide_Wide_String;
564 Count : Natural;
565 Pad : Wide_Wide_Character := Wide_Wide_Space)
567 Old : Wide_Wide_String_Access := Source.Reference;
568 begin
569 Source.Reference :=
570 new Wide_Wide_String'
571 (Wide_Wide_Fixed.Head
572 (Source.Reference (1 .. Source.Last), Count, Pad));
573 Source.Last := Source.Reference'Length;
574 Free (Old);
575 end Head;
577 -----------
578 -- Index --
579 -----------
581 function Index
582 (Source : Unbounded_Wide_Wide_String;
583 Pattern : Wide_Wide_String;
584 Going : Strings.Direction := Strings.Forward;
585 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
586 Wide_Wide_Maps.Identity)
587 return Natural
589 begin
590 return
591 Wide_Wide_Search.Index
592 (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping);
593 end Index;
595 function Index
596 (Source : Unbounded_Wide_Wide_String;
597 Pattern : Wide_Wide_String;
598 Going : Direction := Forward;
599 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
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 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
611 Test : Strings.Membership := Strings.Inside;
612 Going : Strings.Direction := Strings.Forward) return Natural
614 begin
615 return Wide_Wide_Search.Index
616 (Source.Reference (1 .. Source.Last), Set, Test, Going);
617 end Index;
619 function Index
620 (Source : Unbounded_Wide_Wide_String;
621 Pattern : Wide_Wide_String;
622 From : Positive;
623 Going : Direction := Forward;
624 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
625 Wide_Wide_Maps.Identity)
626 return Natural
628 begin
629 return
630 Wide_Wide_Search.Index
631 (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping);
632 end Index;
634 function Index
635 (Source : Unbounded_Wide_Wide_String;
636 Pattern : Wide_Wide_String;
637 From : Positive;
638 Going : Direction := Forward;
639 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
640 return Natural
642 begin
643 return
644 Wide_Wide_Search.Index
645 (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping);
646 end Index;
648 function Index
649 (Source : Unbounded_Wide_Wide_String;
650 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
651 From : Positive;
652 Test : Membership := Inside;
653 Going : Direction := Forward) return Natural
655 begin
656 return
657 Wide_Wide_Search.Index
658 (Source.Reference (1 .. Source.Last), Set, From, Test, Going);
659 end Index;
661 function Index_Non_Blank
662 (Source : Unbounded_Wide_Wide_String;
663 Going : Strings.Direction := Strings.Forward) return Natural
665 begin
666 return
667 Wide_Wide_Search.Index_Non_Blank
668 (Source.Reference (1 .. Source.Last), Going);
669 end Index_Non_Blank;
671 function Index_Non_Blank
672 (Source : Unbounded_Wide_Wide_String;
673 From : Positive;
674 Going : Direction := Forward) return Natural
676 begin
677 return
678 Wide_Wide_Search.Index_Non_Blank
679 (Source.Reference (1 .. Source.Last), From, Going);
680 end Index_Non_Blank;
682 ----------------
683 -- Initialize --
684 ----------------
686 procedure Initialize (Object : in out Unbounded_Wide_Wide_String) is
687 begin
688 Object.Reference := Null_Unbounded_Wide_Wide_String.Reference;
689 Object.Last := 0;
690 end Initialize;
692 ------------
693 -- Insert --
694 ------------
696 function Insert
697 (Source : Unbounded_Wide_Wide_String;
698 Before : Positive;
699 New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String
701 begin
702 return
703 To_Unbounded_Wide_Wide_String
704 (Wide_Wide_Fixed.Insert
705 (Source.Reference (1 .. Source.Last), Before, New_Item));
706 end Insert;
708 procedure Insert
709 (Source : in out Unbounded_Wide_Wide_String;
710 Before : Positive;
711 New_Item : Wide_Wide_String)
713 begin
714 if Before not in Source.Reference'First .. Source.Last + 1 then
715 raise Index_Error;
716 end if;
718 Realloc_For_Chunk (Source, New_Item'Length);
720 Source.Reference
721 (Before + New_Item'Length .. Source.Last + New_Item'Length) :=
722 Source.Reference (Before .. Source.Last);
724 Source.Reference (Before .. Before + New_Item'Length - 1) := New_Item;
725 Source.Last := Source.Last + New_Item'Length;
726 end Insert;
728 ------------
729 -- Length --
730 ------------
732 function Length (Source : Unbounded_Wide_Wide_String) return Natural is
733 begin
734 return Source.Last;
735 end Length;
737 ---------------
738 -- Overwrite --
739 ---------------
741 function Overwrite
742 (Source : Unbounded_Wide_Wide_String;
743 Position : Positive;
744 New_Item : Wide_Wide_String) return Unbounded_Wide_Wide_String
746 begin
747 return
748 To_Unbounded_Wide_Wide_String
749 (Wide_Wide_Fixed.Overwrite
750 (Source.Reference (1 .. Source.Last), Position, New_Item));
751 end Overwrite;
753 procedure Overwrite
754 (Source : in out Unbounded_Wide_Wide_String;
755 Position : Positive;
756 New_Item : Wide_Wide_String)
758 NL : constant Natural := New_Item'Length;
759 begin
760 if Position <= Source.Last - NL + 1 then
761 Source.Reference (Position .. Position + NL - 1) := New_Item;
762 else
763 declare
764 Old : Wide_Wide_String_Access := Source.Reference;
765 begin
766 Source.Reference := new Wide_Wide_String'
767 (Wide_Wide_Fixed.Overwrite
768 (Source.Reference (1 .. Source.Last), Position, New_Item));
769 Source.Last := Source.Reference'Length;
770 Free (Old);
771 end;
772 end if;
773 end Overwrite;
775 -----------------------
776 -- Realloc_For_Chunk --
777 -----------------------
779 procedure Realloc_For_Chunk
780 (Source : in out Unbounded_Wide_Wide_String;
781 Chunk_Size : Natural)
783 Growth_Factor : constant := 32;
784 -- The growth factor controls how much extra space is allocated when
785 -- we have to increase the size of an allocated unbounded string. By
786 -- allocating extra space, we avoid the need to reallocate on every
787 -- append, particularly important when a string is built up by repeated
788 -- append operations of small pieces. This is expressed as a factor so
789 -- 32 means add 1/32 of the length of the string as growth space.
791 Min_Mul_Alloc : constant := Standard'Maximum_Alignment;
792 -- Allocation will be done by a multiple of Min_Mul_Alloc This causes
793 -- no memory loss as most (all?) malloc implementations are obliged to
794 -- align the returned memory on the maximum alignment as malloc does not
795 -- know the target alignment.
797 S_Length : constant Natural := Source.Reference'Length;
799 begin
800 if Chunk_Size > S_Length - Source.Last then
801 declare
802 New_Size : constant Positive :=
803 S_Length + Chunk_Size + (S_Length / Growth_Factor);
805 New_Rounded_Up_Size : constant Positive :=
806 ((New_Size - 1) / Min_Mul_Alloc + 1) *
807 Min_Mul_Alloc;
809 Tmp : constant Wide_Wide_String_Access :=
810 new Wide_Wide_String (1 .. New_Rounded_Up_Size);
812 begin
813 Tmp (1 .. Source.Last) := Source.Reference (1 .. Source.Last);
814 Free (Source.Reference);
815 Source.Reference := Tmp;
816 end;
817 end if;
818 end Realloc_For_Chunk;
820 ---------------------
821 -- Replace_Element --
822 ---------------------
824 procedure Replace_Element
825 (Source : in out Unbounded_Wide_Wide_String;
826 Index : Positive;
827 By : Wide_Wide_Character)
829 begin
830 if Index <= Source.Last then
831 Source.Reference (Index) := By;
832 else
833 raise Strings.Index_Error;
834 end if;
835 end Replace_Element;
837 -------------------
838 -- Replace_Slice --
839 -------------------
841 function Replace_Slice
842 (Source : Unbounded_Wide_Wide_String;
843 Low : Positive;
844 High : Natural;
845 By : Wide_Wide_String) return Unbounded_Wide_Wide_String
847 begin
848 return To_Unbounded_Wide_Wide_String
849 (Wide_Wide_Fixed.Replace_Slice
850 (Source.Reference (1 .. Source.Last), Low, High, By));
851 end Replace_Slice;
853 procedure Replace_Slice
854 (Source : in out Unbounded_Wide_Wide_String;
855 Low : Positive;
856 High : Natural;
857 By : Wide_Wide_String)
859 Old : Wide_Wide_String_Access := Source.Reference;
860 begin
861 Source.Reference := new Wide_Wide_String'
862 (Wide_Wide_Fixed.Replace_Slice
863 (Source.Reference (1 .. Source.Last), Low, High, By));
864 Source.Last := Source.Reference'Length;
865 Free (Old);
866 end Replace_Slice;
868 ------------------------------------
869 -- Set_Unbounded_Wide_Wide_String --
870 ------------------------------------
872 procedure Set_Unbounded_Wide_Wide_String
873 (Target : out Unbounded_Wide_Wide_String;
874 Source : Wide_Wide_String)
876 begin
877 Target.Last := Source'Length;
878 Target.Reference := new Wide_Wide_String (1 .. Source'Length);
879 Target.Reference.all := Source;
880 end Set_Unbounded_Wide_Wide_String;
882 -----------
883 -- Slice --
884 -----------
886 function Slice
887 (Source : Unbounded_Wide_Wide_String;
888 Low : Positive;
889 High : Natural) return Wide_Wide_String
891 begin
892 -- Note: test of High > Length is in accordance with AI95-00128
894 if Low > Source.Last + 1 or else High > Source.Last then
895 raise Index_Error;
896 else
897 return Source.Reference (Low .. High);
898 end if;
899 end Slice;
901 ----------
902 -- Tail --
903 ----------
905 function Tail
906 (Source : Unbounded_Wide_Wide_String;
907 Count : Natural;
908 Pad : Wide_Wide_Character := Wide_Wide_Space)
909 return Unbounded_Wide_Wide_String is
910 begin
911 return To_Unbounded_Wide_Wide_String
912 (Wide_Wide_Fixed.Tail
913 (Source.Reference (1 .. Source.Last), Count, Pad));
914 end Tail;
916 procedure Tail
917 (Source : in out Unbounded_Wide_Wide_String;
918 Count : Natural;
919 Pad : Wide_Wide_Character := Wide_Wide_Space)
921 Old : Wide_Wide_String_Access := Source.Reference;
922 begin
923 Source.Reference := new Wide_Wide_String'
924 (Wide_Wide_Fixed.Tail
925 (Source.Reference (1 .. Source.Last), Count, Pad));
926 Source.Last := Source.Reference'Length;
927 Free (Old);
928 end Tail;
930 -----------------------------------
931 -- To_Unbounded_Wide_Wide_String --
932 -----------------------------------
934 function To_Unbounded_Wide_Wide_String
935 (Source : Wide_Wide_String) return Unbounded_Wide_Wide_String
937 Result : Unbounded_Wide_Wide_String;
938 begin
939 Result.Last := Source'Length;
940 Result.Reference := new Wide_Wide_String (1 .. Source'Length);
941 Result.Reference.all := Source;
942 return Result;
943 end To_Unbounded_Wide_Wide_String;
945 function To_Unbounded_Wide_Wide_String
946 (Length : Natural) return Unbounded_Wide_Wide_String
948 Result : Unbounded_Wide_Wide_String;
949 begin
950 Result.Last := Length;
951 Result.Reference := new Wide_Wide_String (1 .. Length);
952 return Result;
953 end To_Unbounded_Wide_Wide_String;
955 -------------------------
956 -- To_Wide_Wide_String --
957 -------------------------
959 function To_Wide_Wide_String
960 (Source : Unbounded_Wide_Wide_String) return Wide_Wide_String
962 begin
963 return Source.Reference (1 .. Source.Last);
964 end To_Wide_Wide_String;
966 ---------------
967 -- Translate --
968 ---------------
970 function Translate
971 (Source : Unbounded_Wide_Wide_String;
972 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
973 return Unbounded_Wide_Wide_String
975 begin
976 return
977 To_Unbounded_Wide_Wide_String
978 (Wide_Wide_Fixed.Translate
979 (Source.Reference (1 .. Source.Last), Mapping));
980 end Translate;
982 procedure Translate
983 (Source : in out Unbounded_Wide_Wide_String;
984 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
986 begin
987 Wide_Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping);
988 end Translate;
990 function Translate
991 (Source : Unbounded_Wide_Wide_String;
992 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
993 return Unbounded_Wide_Wide_String
995 begin
996 return
997 To_Unbounded_Wide_Wide_String
998 (Wide_Wide_Fixed.Translate
999 (Source.Reference (1 .. Source.Last), Mapping));
1000 end Translate;
1002 procedure Translate
1003 (Source : in out Unbounded_Wide_Wide_String;
1004 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
1006 begin
1007 Wide_Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping);
1008 end Translate;
1010 ----------
1011 -- Trim --
1012 ----------
1014 function Trim
1015 (Source : Unbounded_Wide_Wide_String;
1016 Side : Trim_End) return Unbounded_Wide_Wide_String
1018 begin
1019 return
1020 To_Unbounded_Wide_Wide_String
1021 (Wide_Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side));
1022 end Trim;
1024 procedure Trim
1025 (Source : in out Unbounded_Wide_Wide_String;
1026 Side : Trim_End)
1028 Old : Wide_Wide_String_Access := Source.Reference;
1029 begin
1030 Source.Reference :=
1031 new Wide_Wide_String'
1032 (Wide_Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side));
1033 Source.Last := Source.Reference'Length;
1034 Free (Old);
1035 end Trim;
1037 function Trim
1038 (Source : Unbounded_Wide_Wide_String;
1039 Left : Wide_Wide_Maps.Wide_Wide_Character_Set;
1040 Right : Wide_Wide_Maps.Wide_Wide_Character_Set)
1041 return Unbounded_Wide_Wide_String
1043 begin
1044 return
1045 To_Unbounded_Wide_Wide_String
1046 (Wide_Wide_Fixed.Trim
1047 (Source.Reference (1 .. Source.Last), Left, Right));
1048 end Trim;
1050 procedure Trim
1051 (Source : in out Unbounded_Wide_Wide_String;
1052 Left : Wide_Wide_Maps.Wide_Wide_Character_Set;
1053 Right : Wide_Wide_Maps.Wide_Wide_Character_Set)
1055 Old : Wide_Wide_String_Access := Source.Reference;
1056 begin
1057 Source.Reference :=
1058 new Wide_Wide_String'
1059 (Wide_Wide_Fixed.Trim
1060 (Source.Reference (1 .. Source.Last), Left, Right));
1061 Source.Last := Source.Reference'Length;
1062 Free (Old);
1063 end Trim;
1065 ---------------------
1066 -- Unbounded_Slice --
1067 ---------------------
1069 function Unbounded_Slice
1070 (Source : Unbounded_Wide_Wide_String;
1071 Low : Positive;
1072 High : Natural) return Unbounded_Wide_Wide_String
1074 begin
1075 if Low > Source.Last + 1 or else High > Source.Last then
1076 raise Index_Error;
1077 else
1078 return
1079 To_Unbounded_Wide_Wide_String (Source.Reference.all (Low .. High));
1080 end if;
1081 end Unbounded_Slice;
1083 procedure Unbounded_Slice
1084 (Source : Unbounded_Wide_Wide_String;
1085 Target : out Unbounded_Wide_Wide_String;
1086 Low : Positive;
1087 High : Natural)
1089 begin
1090 if Low > Source.Last + 1 or else High > Source.Last then
1091 raise Index_Error;
1092 else
1093 Target :=
1094 To_Unbounded_Wide_Wide_String (Source.Reference.all (Low .. High));
1095 end if;
1096 end Unbounded_Slice;
1098 end Ada.Strings.Wide_Wide_Unbounded;