* arm.c (FL_WBUF): Define.
[official-gcc.git] / gcc / ada / a-stwiun.adb
blobe722111c8db383d6d95d24c6b2a8dfa7ace03f49
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME 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 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with Ada.Strings.Wide_Fixed;
35 with Ada.Strings.Wide_Search;
36 with Ada.Unchecked_Deallocation;
38 package body Ada.Strings.Wide_Unbounded is
40 use Ada.Finalization;
42 ---------
43 -- "&" --
44 ---------
46 function "&"
47 (Left : Unbounded_Wide_String;
48 Right : Unbounded_Wide_String) return Unbounded_Wide_String
50 L_Length : constant Natural := Left.Last;
51 R_Length : constant Natural := Right.Last;
52 Result : Unbounded_Wide_String;
54 begin
55 Result.Last := L_Length + R_Length;
57 Result.Reference := new Wide_String (1 .. Result.Last);
59 Result.Reference (1 .. L_Length) :=
60 Left.Reference (1 .. Left.Last);
61 Result.Reference (L_Length + 1 .. Result.Last) :=
62 Right.Reference (1 .. Right.Last);
64 return Result;
65 end "&";
67 function "&"
68 (Left : Unbounded_Wide_String;
69 Right : Wide_String) return Unbounded_Wide_String
71 L_Length : constant Natural := Left.Last;
72 Result : Unbounded_Wide_String;
74 begin
75 Result.Last := L_Length + Right'Length;
77 Result.Reference := new Wide_String (1 .. Result.Last);
79 Result.Reference (1 .. L_Length) := Left.Reference (1 .. Left.Last);
80 Result.Reference (L_Length + 1 .. Result.Last) := Right;
82 return Result;
83 end "&";
85 function "&"
86 (Left : Wide_String;
87 Right : Unbounded_Wide_String) return Unbounded_Wide_String
89 R_Length : constant Natural := Right.Last;
90 Result : Unbounded_Wide_String;
92 begin
93 Result.Last := Left'Length + R_Length;
95 Result.Reference := new Wide_String (1 .. Result.Last);
97 Result.Reference (1 .. Left'Length) := Left;
98 Result.Reference (Left'Length + 1 .. Result.Last) :=
99 Right.Reference (1 .. Right.Last);
101 return Result;
102 end "&";
104 function "&"
105 (Left : Unbounded_Wide_String;
106 Right : Wide_Character) return Unbounded_Wide_String
108 Result : Unbounded_Wide_String;
110 begin
111 Result.Last := Left.Last + 1;
113 Result.Reference := new Wide_String (1 .. Result.Last);
115 Result.Reference (1 .. Result.Last - 1) :=
116 Left.Reference (1 .. Left.Last);
117 Result.Reference (Result.Last) := Right;
119 return Result;
120 end "&";
122 function "&"
123 (Left : Wide_Character;
124 Right : Unbounded_Wide_String) return Unbounded_Wide_String
126 Result : Unbounded_Wide_String;
128 begin
129 Result.Last := Right.Last + 1;
131 Result.Reference := new Wide_String (1 .. Result.Last);
132 Result.Reference (1) := Left;
133 Result.Reference (2 .. Result.Last) :=
134 Right.Reference (1 .. Right.Last);
135 return Result;
136 end "&";
138 ---------
139 -- "*" --
140 ---------
142 function "*"
143 (Left : Natural;
144 Right : Wide_Character) return Unbounded_Wide_String
146 Result : Unbounded_Wide_String;
148 begin
149 Result.Last := Left;
151 Result.Reference := new Wide_String (1 .. Left);
152 for J in Result.Reference'Range loop
153 Result.Reference (J) := Right;
154 end loop;
156 return Result;
157 end "*";
159 function "*"
160 (Left : Natural;
161 Right : Wide_String) return Unbounded_Wide_String
163 Len : constant Natural := Right'Length;
164 K : Positive;
165 Result : Unbounded_Wide_String;
167 begin
168 Result.Last := Left * Len;
170 Result.Reference := new Wide_String (1 .. Result.Last);
172 K := 1;
173 for J in 1 .. Left loop
174 Result.Reference (K .. K + Len - 1) := Right;
175 K := K + Len;
176 end loop;
178 return Result;
179 end "*";
181 function "*"
182 (Left : Natural;
183 Right : Unbounded_Wide_String) return Unbounded_Wide_String
185 Len : constant Natural := Right.Last;
186 K : Positive;
187 Result : Unbounded_Wide_String;
189 begin
190 Result.Last := Left * Len;
192 Result.Reference := new Wide_String (1 .. Result.Last);
194 K := 1;
195 for J in 1 .. Left loop
196 Result.Reference (K .. K + Len - 1) :=
197 Right.Reference (1 .. Right.Last);
198 K := K + Len;
199 end loop;
201 return Result;
202 end "*";
204 ---------
205 -- "<" --
206 ---------
208 function "<"
209 (Left : Unbounded_Wide_String;
210 Right : Unbounded_Wide_String) return Boolean
212 begin
213 return
214 Left.Reference (1 .. Left.Last) < Right.Reference (1 .. Right.Last);
215 end "<";
217 function "<"
218 (Left : Unbounded_Wide_String;
219 Right : Wide_String) return Boolean
221 begin
222 return Left.Reference (1 .. Left.Last) < Right;
223 end "<";
225 function "<"
226 (Left : Wide_String;
227 Right : Unbounded_Wide_String) return Boolean
229 begin
230 return Left < Right.Reference (1 .. Right.Last);
231 end "<";
233 ----------
234 -- "<=" --
235 ----------
237 function "<="
238 (Left : Unbounded_Wide_String;
239 Right : Unbounded_Wide_String) return Boolean
241 begin
242 return
243 Left.Reference (1 .. Left.Last) <= Right.Reference (1 .. Right.Last);
244 end "<=";
246 function "<="
247 (Left : Unbounded_Wide_String;
248 Right : Wide_String) return Boolean
250 begin
251 return Left.Reference (1 .. Left.Last) <= Right;
252 end "<=";
254 function "<="
255 (Left : Wide_String;
256 Right : Unbounded_Wide_String) return Boolean
258 begin
259 return Left <= Right.Reference (1 .. Right.Last);
260 end "<=";
262 ---------
263 -- "=" --
264 ---------
266 function "="
267 (Left : Unbounded_Wide_String;
268 Right : Unbounded_Wide_String) return Boolean
270 begin
271 return
272 Left.Reference (1 .. Left.Last) = Right.Reference (1 .. Right.Last);
273 end "=";
275 function "="
276 (Left : Unbounded_Wide_String;
277 Right : Wide_String) return Boolean
279 begin
280 return Left.Reference (1 .. Left.Last) = Right;
281 end "=";
283 function "="
284 (Left : Wide_String;
285 Right : Unbounded_Wide_String) return Boolean
287 begin
288 return Left = Right.Reference (1 .. Right.Last);
289 end "=";
291 ---------
292 -- ">" --
293 ---------
295 function ">"
296 (Left : Unbounded_Wide_String;
297 Right : Unbounded_Wide_String) return Boolean
299 begin
300 return
301 Left.Reference (1 .. Left.Last) > Right.Reference (1 .. Right.Last);
302 end ">";
304 function ">"
305 (Left : Unbounded_Wide_String;
306 Right : Wide_String) return Boolean
308 begin
309 return Left.Reference (1 .. Left.Last) > Right;
310 end ">";
312 function ">"
313 (Left : Wide_String;
314 Right : Unbounded_Wide_String) return Boolean
316 begin
317 return Left > Right.Reference (1 .. Right.Last);
318 end ">";
320 ----------
321 -- ">=" --
322 ----------
324 function ">="
325 (Left : Unbounded_Wide_String;
326 Right : Unbounded_Wide_String) return Boolean
328 begin
329 return
330 Left.Reference (1 .. Left.Last) >= Right.Reference (1 .. Right.Last);
331 end ">=";
333 function ">="
334 (Left : Unbounded_Wide_String;
335 Right : Wide_String) return Boolean
337 begin
338 return Left.Reference (1 .. Left.Last) >= Right;
339 end ">=";
341 function ">="
342 (Left : Wide_String;
343 Right : Unbounded_Wide_String) return Boolean
345 begin
346 return Left >= Right.Reference (1 .. Right.Last);
347 end ">=";
349 ------------
350 -- Adjust --
351 ------------
353 procedure Adjust (Object : in out Unbounded_Wide_String) is
354 begin
355 -- Copy string, except we do not copy the statically allocated null
356 -- string, since it can never be deallocated. Note that we do not copy
357 -- extra string room here to avoid dragging unused allocated memory.
359 if Object.Reference /= Null_Wide_String'Access then
360 Object.Reference :=
361 new Wide_String'(Object.Reference (1 .. Object.Last));
362 end if;
363 end Adjust;
365 ------------
366 -- Append --
367 ------------
369 procedure Append
370 (Source : in out Unbounded_Wide_String;
371 New_Item : Unbounded_Wide_String)
373 begin
374 Realloc_For_Chunk (Source, New_Item.Last);
375 Source.Reference (Source.Last + 1 .. Source.Last + New_Item.Last) :=
376 New_Item.Reference (1 .. New_Item.Last);
377 Source.Last := Source.Last + New_Item.Last;
378 end Append;
380 procedure Append
381 (Source : in out Unbounded_Wide_String;
382 New_Item : Wide_String)
384 begin
385 Realloc_For_Chunk (Source, New_Item'Length);
386 Source.Reference (Source.Last + 1 .. Source.Last + New_Item'Length) :=
387 New_Item;
388 Source.Last := Source.Last + New_Item'Length;
389 end Append;
391 procedure Append
392 (Source : in out Unbounded_Wide_String;
393 New_Item : Wide_Character)
395 begin
396 Realloc_For_Chunk (Source, 1);
397 Source.Reference (Source.Last + 1) := New_Item;
398 Source.Last := Source.Last + 1;
399 end Append;
401 -----------
402 -- Count --
403 -----------
405 function Count
406 (Source : Unbounded_Wide_String;
407 Pattern : Wide_String;
408 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
409 return Natural
411 begin
412 return
413 Wide_Search.Count
414 (Source.Reference (1 .. Source.Last), Pattern, Mapping);
415 end Count;
417 function Count
418 (Source : Unbounded_Wide_String;
419 Pattern : Wide_String;
420 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural
422 begin
423 return
424 Wide_Search.Count
425 (Source.Reference (1 .. Source.Last), Pattern, Mapping);
426 end Count;
428 function Count
429 (Source : Unbounded_Wide_String;
430 Set : Wide_Maps.Wide_Character_Set) return Natural
432 begin
433 return
434 Wide_Search.Count
435 (Source.Reference (1 .. Source.Last), Set);
436 end Count;
438 ------------
439 -- Delete --
440 ------------
442 function Delete
443 (Source : Unbounded_Wide_String;
444 From : Positive;
445 Through : Natural) return Unbounded_Wide_String
447 begin
448 return
449 To_Unbounded_Wide_String
450 (Wide_Fixed.Delete
451 (Source.Reference (1 .. Source.Last), From, Through));
452 end Delete;
454 procedure Delete
455 (Source : in out Unbounded_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_String;
484 Index : Positive) return 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_String) is
499 procedure Deallocate is
500 new Ada.Unchecked_Deallocation (Wide_String, Wide_String_Access);
502 begin
503 -- Note: Don't try to free statically allocated null string
505 if Object.Reference /= Null_Wide_String'Access then
506 Deallocate (Object.Reference);
507 Object.Reference := Null_Unbounded_Wide_String.Reference;
508 Object.Last := 0;
509 end if;
510 end Finalize;
512 ----------------
513 -- Find_Token --
514 ----------------
516 procedure Find_Token
517 (Source : Unbounded_Wide_String;
518 Set : Wide_Maps.Wide_Character_Set;
519 Test : Strings.Membership;
520 First : out Positive;
521 Last : out Natural)
523 begin
524 Wide_Search.Find_Token
525 (Source.Reference (1 .. Source.Last), Set, Test, First, Last);
526 end Find_Token;
528 ----------
529 -- Free --
530 ----------
532 procedure Free (X : in out Wide_String_Access) is
533 procedure Deallocate is
534 new Ada.Unchecked_Deallocation (Wide_String, Wide_String_Access);
536 begin
537 -- Note: Do not try to free statically allocated null string
539 if X /= Null_Unbounded_Wide_String.Reference then
540 Deallocate (X);
541 end if;
542 end Free;
544 ----------
545 -- Head --
546 ----------
548 function Head
549 (Source : Unbounded_Wide_String;
550 Count : Natural;
551 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String
553 begin
554 return To_Unbounded_Wide_String
555 (Wide_Fixed.Head (Source.Reference (1 .. Source.Last), Count, Pad));
556 end Head;
558 procedure Head
559 (Source : in out Unbounded_Wide_String;
560 Count : Natural;
561 Pad : Wide_Character := Wide_Space)
563 Old : Wide_String_Access := Source.Reference;
564 begin
565 Source.Reference :=
566 new Wide_String'
567 (Wide_Fixed.Head (Source.Reference (1 .. Source.Last), Count, Pad));
568 Source.Last := Source.Reference'Length;
569 Free (Old);
570 end Head;
572 -----------
573 -- Index --
574 -----------
576 function Index
577 (Source : Unbounded_Wide_String;
578 Pattern : Wide_String;
579 Going : Strings.Direction := Strings.Forward;
580 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
581 return Natural
583 begin
584 return
585 Wide_Search.Index
586 (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping);
587 end Index;
589 function Index
590 (Source : Unbounded_Wide_String;
591 Pattern : Wide_String;
592 Going : Direction := Forward;
593 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural
595 begin
596 return
597 Wide_Search.Index
598 (Source.Reference (1 .. Source.Last), Pattern, Going, Mapping);
599 end Index;
601 function Index
602 (Source : Unbounded_Wide_String;
603 Set : Wide_Maps.Wide_Character_Set;
604 Test : Strings.Membership := Strings.Inside;
605 Going : Strings.Direction := Strings.Forward) return Natural
607 begin
608 return Wide_Search.Index
609 (Source.Reference (1 .. Source.Last), Set, Test, Going);
610 end Index;
612 function Index
613 (Source : Unbounded_Wide_String;
614 Pattern : Wide_String;
615 From : Positive;
616 Going : Direction := Forward;
617 Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
618 return Natural
620 begin
621 return
622 Wide_Search.Index
623 (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping);
624 end Index;
626 function Index
627 (Source : Unbounded_Wide_String;
628 Pattern : Wide_String;
629 From : Positive;
630 Going : Direction := Forward;
631 Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural
633 begin
634 return
635 Wide_Search.Index
636 (Source.Reference (1 .. Source.Last), Pattern, From, Going, Mapping);
637 end Index;
640 function Index
641 (Source : Unbounded_Wide_String;
642 Set : Wide_Maps.Wide_Character_Set;
643 From : Positive;
644 Test : Membership := Inside;
645 Going : Direction := Forward) return Natural
647 begin
648 return
649 Wide_Search.Index
650 (Source.Reference (1 .. Source.Last), Set, From, Test, Going);
651 end Index;
653 function Index_Non_Blank
654 (Source : Unbounded_Wide_String;
655 Going : Strings.Direction := Strings.Forward) return Natural
657 begin
658 return
659 Wide_Search.Index_Non_Blank
660 (Source.Reference (1 .. Source.Last), Going);
661 end Index_Non_Blank;
663 function Index_Non_Blank
664 (Source : Unbounded_Wide_String;
665 From : Positive;
666 Going : Direction := Forward) return Natural
668 begin
669 return
670 Wide_Search.Index_Non_Blank
671 (Source.Reference (1 .. Source.Last), From, Going);
672 end Index_Non_Blank;
674 ----------------
675 -- Initialize --
676 ----------------
678 procedure Initialize (Object : in out Unbounded_Wide_String) is
679 begin
680 Object.Reference := Null_Unbounded_Wide_String.Reference;
681 Object.Last := 0;
682 end Initialize;
684 ------------
685 -- Insert --
686 ------------
688 function Insert
689 (Source : Unbounded_Wide_String;
690 Before : Positive;
691 New_Item : Wide_String) return Unbounded_Wide_String
693 begin
694 return
695 To_Unbounded_Wide_String
696 (Wide_Fixed.Insert
697 (Source.Reference (1 .. Source.Last), Before, New_Item));
698 end Insert;
700 procedure Insert
701 (Source : in out Unbounded_Wide_String;
702 Before : Positive;
703 New_Item : Wide_String)
705 begin
706 if Before not in Source.Reference'First .. Source.Last + 1 then
707 raise Index_Error;
708 end if;
710 Realloc_For_Chunk (Source, New_Item'Size);
712 Source.Reference
713 (Before + New_Item'Length .. Source.Last + New_Item'Length) :=
714 Source.Reference (Before .. Source.Last);
716 Source.Reference (Before .. Before + New_Item'Length - 1) := New_Item;
717 Source.Last := Source.Last + New_Item'Length;
718 end Insert;
720 ------------
721 -- Length --
722 ------------
724 function Length (Source : Unbounded_Wide_String) return Natural is
725 begin
726 return Source.Last;
727 end Length;
729 ---------------
730 -- Overwrite --
731 ---------------
733 function Overwrite
734 (Source : Unbounded_Wide_String;
735 Position : Positive;
736 New_Item : Wide_String) return Unbounded_Wide_String
738 begin
739 return
740 To_Unbounded_Wide_String
741 (Wide_Fixed.Overwrite
742 (Source.Reference (1 .. Source.Last), Position, New_Item));
743 end Overwrite;
745 procedure Overwrite
746 (Source : in out Unbounded_Wide_String;
747 Position : Positive;
748 New_Item : Wide_String)
750 NL : constant Natural := New_Item'Length;
751 begin
752 if Position <= Source.Last - NL + 1 then
753 Source.Reference (Position .. Position + NL - 1) := New_Item;
754 else
755 declare
756 Old : Wide_String_Access := Source.Reference;
757 begin
758 Source.Reference := new Wide_String'
759 (Wide_Fixed.Overwrite
760 (Source.Reference (1 .. Source.Last), Position, New_Item));
761 Source.Last := Source.Reference'Length;
762 Free (Old);
763 end;
764 end if;
765 end Overwrite;
767 -----------------------
768 -- Realloc_For_Chunk --
769 -----------------------
771 procedure Realloc_For_Chunk
772 (Source : in out Unbounded_Wide_String;
773 Chunk_Size : Natural)
775 Growth_Factor : constant := 50;
776 S_Length : constant Natural := Source.Reference'Length;
778 begin
779 if Chunk_Size > S_Length - Source.Last then
780 declare
781 Alloc_Chunk_Size : constant Positive :=
782 Chunk_Size + (S_Length / Growth_Factor);
783 Tmp : Wide_String_Access;
784 begin
785 Tmp := new Wide_String (1 .. S_Length + Alloc_Chunk_Size);
786 Tmp (1 .. Source.Last) := Source.Reference (1 .. Source.Last);
787 Free (Source.Reference);
788 Source.Reference := Tmp;
789 end;
790 end if;
791 end Realloc_For_Chunk;
793 ---------------------
794 -- Replace_Element --
795 ---------------------
797 procedure Replace_Element
798 (Source : in out Unbounded_Wide_String;
799 Index : Positive;
800 By : Wide_Character)
802 begin
803 if Index <= Source.Last then
804 Source.Reference (Index) := By;
805 else
806 raise Strings.Index_Error;
807 end if;
808 end Replace_Element;
810 -------------------
811 -- Replace_Slice --
812 -------------------
814 function Replace_Slice
815 (Source : Unbounded_Wide_String;
816 Low : Positive;
817 High : Natural;
818 By : Wide_String) return Unbounded_Wide_String
820 begin
821 return To_Unbounded_Wide_String
822 (Wide_Fixed.Replace_Slice
823 (Source.Reference (1 .. Source.Last), Low, High, By));
824 end Replace_Slice;
826 procedure Replace_Slice
827 (Source : in out Unbounded_Wide_String;
828 Low : Positive;
829 High : Natural;
830 By : Wide_String)
832 Old : Wide_String_Access := Source.Reference;
833 begin
834 Source.Reference := new Wide_String'
835 (Wide_Fixed.Replace_Slice
836 (Source.Reference (1 .. Source.Last), Low, High, By));
837 Source.Last := Source.Reference'Length;
838 Free (Old);
839 end Replace_Slice;
841 -------------------------------
842 -- Set_Unbounded_Wide_String --
843 -------------------------------
845 procedure Set_Unbounded_Wide_String
846 (Target : out Unbounded_Wide_String;
847 Source : Wide_String)
849 begin
850 Target.Last := Source'Length;
851 Target.Reference := new Wide_String (1 .. Source'Length);
852 Target.Reference.all := Source;
853 end Set_Unbounded_Wide_String;
855 -----------
856 -- Slice --
857 -----------
859 function Slice
860 (Source : Unbounded_Wide_String;
861 Low : Positive;
862 High : Natural) return Wide_String
864 begin
865 -- Note: test of High > Length is in accordance with AI95-00128
867 if Low > Source.Last + 1 or else High > Source.Last then
868 raise Index_Error;
869 else
870 return Source.Reference (Low .. High);
871 end if;
872 end Slice;
874 ----------
875 -- Tail --
876 ----------
878 function Tail
879 (Source : Unbounded_Wide_String;
880 Count : Natural;
881 Pad : Wide_Character := Wide_Space) return Unbounded_Wide_String is
882 begin
883 return To_Unbounded_Wide_String
884 (Wide_Fixed.Tail (Source.Reference (1 .. Source.Last), Count, Pad));
885 end Tail;
887 procedure Tail
888 (Source : in out Unbounded_Wide_String;
889 Count : Natural;
890 Pad : Wide_Character := Wide_Space)
892 Old : Wide_String_Access := Source.Reference;
893 begin
894 Source.Reference := new Wide_String'
895 (Wide_Fixed.Tail (Source.Reference (1 .. Source.Last), Count, Pad));
896 Source.Last := Source.Reference'Length;
897 Free (Old);
898 end Tail;
900 ------------------------------
901 -- To_Unbounded_Wide_String --
902 ------------------------------
904 function To_Unbounded_Wide_String
905 (Source : Wide_String)
906 return Unbounded_Wide_String
908 Result : Unbounded_Wide_String;
909 begin
910 Result.Last := Source'Length;
911 Result.Reference := new Wide_String (1 .. Source'Length);
912 Result.Reference.all := Source;
913 return Result;
914 end To_Unbounded_Wide_String;
916 function To_Unbounded_Wide_String
917 (Length : Natural) return Unbounded_Wide_String
919 Result : Unbounded_Wide_String;
920 begin
921 Result.Last := Length;
922 Result.Reference := new Wide_String (1 .. Length);
923 return Result;
924 end To_Unbounded_Wide_String;
926 -------------------
927 -- To_Wide_String --
928 --------------------
930 function To_Wide_String
931 (Source : Unbounded_Wide_String)
932 return Wide_String
934 begin
935 return Source.Reference (1 .. Source.Last);
936 end To_Wide_String;
939 ---------------
940 -- Translate --
941 ---------------
943 function Translate
944 (Source : Unbounded_Wide_String;
945 Mapping : Wide_Maps.Wide_Character_Mapping)
946 return Unbounded_Wide_String
948 begin
949 return
950 To_Unbounded_Wide_String
951 (Wide_Fixed.Translate
952 (Source.Reference (1 .. Source.Last), Mapping));
953 end Translate;
955 procedure Translate
956 (Source : in out Unbounded_Wide_String;
957 Mapping : Wide_Maps.Wide_Character_Mapping)
959 begin
960 Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping);
961 end Translate;
963 function Translate
964 (Source : Unbounded_Wide_String;
965 Mapping : Wide_Maps.Wide_Character_Mapping_Function)
966 return Unbounded_Wide_String
968 begin
969 return
970 To_Unbounded_Wide_String
971 (Wide_Fixed.Translate
972 (Source.Reference (1 .. Source.Last), Mapping));
973 end Translate;
975 procedure Translate
976 (Source : in out Unbounded_Wide_String;
977 Mapping : Wide_Maps.Wide_Character_Mapping_Function)
979 begin
980 Wide_Fixed.Translate (Source.Reference (1 .. Source.Last), Mapping);
981 end Translate;
983 ----------
984 -- Trim --
985 ----------
987 function Trim
988 (Source : Unbounded_Wide_String;
989 Side : Trim_End) return Unbounded_Wide_String
991 begin
992 return
993 To_Unbounded_Wide_String
994 (Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side));
995 end Trim;
997 procedure Trim
998 (Source : in out Unbounded_Wide_String;
999 Side : Trim_End)
1001 Old : Wide_String_Access := Source.Reference;
1002 begin
1003 Source.Reference :=
1004 new Wide_String'
1005 (Wide_Fixed.Trim (Source.Reference (1 .. Source.Last), Side));
1006 Source.Last := Source.Reference'Length;
1007 Free (Old);
1008 end Trim;
1010 function Trim
1011 (Source : Unbounded_Wide_String;
1012 Left : Wide_Maps.Wide_Character_Set;
1013 Right : Wide_Maps.Wide_Character_Set)
1014 return Unbounded_Wide_String
1016 begin
1017 return
1018 To_Unbounded_Wide_String
1019 (Wide_Fixed.Trim
1020 (Source.Reference (1 .. Source.Last), Left, Right));
1021 end Trim;
1023 procedure Trim
1024 (Source : in out Unbounded_Wide_String;
1025 Left : Wide_Maps.Wide_Character_Set;
1026 Right : Wide_Maps.Wide_Character_Set)
1028 Old : Wide_String_Access := Source.Reference;
1029 begin
1030 Source.Reference :=
1031 new Wide_String'
1032 (Wide_Fixed.Trim
1033 (Source.Reference (1 .. Source.Last), Left, Right));
1034 Source.Last := Source.Reference'Length;
1035 Free (Old);
1036 end Trim;
1038 ---------------------
1039 -- Unbounded_Slice --
1040 ---------------------
1042 function Unbounded_Slice
1043 (Source : Unbounded_Wide_String;
1044 Low : Positive;
1045 High : Natural) return Unbounded_Wide_String
1047 begin
1048 if Low > Source.Last + 1 or else High > Source.Last then
1049 raise Index_Error;
1050 else
1051 return To_Unbounded_Wide_String (Source.Reference.all (Low .. High));
1052 end if;
1053 end Unbounded_Slice;
1055 procedure Unbounded_Slice
1056 (Source : Unbounded_Wide_String;
1057 Target : out Unbounded_Wide_String;
1058 Low : Positive;
1059 High : Natural)
1061 begin
1062 if Low > Source.Last + 1 or else High > Source.Last then
1063 raise Index_Error;
1064 else
1065 Target :=
1066 To_Unbounded_Wide_String (Source.Reference.all (Low .. High));
1067 end if;
1068 end Unbounded_Slice;
1070 end Ada.Strings.Wide_Unbounded;