OSDN Git Service

New Language: Ada
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-stwiun.adb
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 --                            $Revision: 1.14 $
10 --                                                                          --
11 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNAT was originally developed  by the GNAT team at  New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 with Ada.Strings.Wide_Fixed;
37 with Ada.Strings.Wide_Search;
38 with Ada.Unchecked_Deallocation;
39
40 package body Ada.Strings.Wide_Unbounded is
41
42    use Ada.Finalization;
43
44    ---------
45    -- "&" --
46    ---------
47
48    function "&"
49      (Left  : Unbounded_Wide_String;
50       Right : Unbounded_Wide_String)
51       return  Unbounded_Wide_String
52    is
53       L_Length : constant Integer := Left.Reference.all'Length;
54       R_Length : constant Integer := Right.Reference.all'Length;
55       Length   : constant Integer := L_Length + R_Length;
56       Result   : Unbounded_Wide_String;
57
58    begin
59       Result.Reference := new Wide_String (1 .. Length);
60       Result.Reference.all (1 .. L_Length)          := Left.Reference.all;
61       Result.Reference.all (L_Length + 1 .. Length) := Right.Reference.all;
62       return Result;
63    end "&";
64
65    function "&"
66      (Left  : Unbounded_Wide_String;
67       Right : Wide_String)
68       return  Unbounded_Wide_String
69    is
70       L_Length : constant Integer := Left.Reference.all'Length;
71       Length   : constant Integer := L_Length +  Right'Length;
72       Result   : Unbounded_Wide_String;
73
74    begin
75       Result.Reference := new Wide_String (1 .. Length);
76       Result.Reference.all (1 .. L_Length)          := Left.Reference.all;
77       Result.Reference.all (L_Length + 1 .. Length) := Right;
78       return Result;
79    end "&";
80
81    function "&"
82      (Left  : Wide_String;
83       Right : Unbounded_Wide_String)
84       return  Unbounded_Wide_String
85    is
86       R_Length : constant Integer := Right.Reference.all'Length;
87       Length   : constant Integer := Left'Length + R_Length;
88       Result   : Unbounded_Wide_String;
89
90    begin
91       Result.Reference := new Wide_String (1 .. Length);
92       Result.Reference.all (1 .. Left'Length)          := Left;
93       Result.Reference.all (Left'Length + 1 .. Length) := Right.Reference.all;
94       return Result;
95    end "&";
96
97    function "&"
98      (Left  : Unbounded_Wide_String;
99       Right : Wide_Character)
100       return  Unbounded_Wide_String
101    is
102       Length : constant Integer := Left.Reference.all'Length + 1;
103       Result : Unbounded_Wide_String;
104
105    begin
106       Result.Reference := new Wide_String (1 .. Length);
107       Result.Reference.all (1 .. Length - 1) := Left.Reference.all;
108       Result.Reference.all (Length)          := Right;
109       return Result;
110    end "&";
111
112    function "&"
113      (Left  : Wide_Character;
114       Right : Unbounded_Wide_String)
115       return  Unbounded_Wide_String
116    is
117       Length : constant Integer      := Right.Reference.all'Length + 1;
118       Result : Unbounded_Wide_String;
119
120    begin
121       Result.Reference := new Wide_String (1 .. Length);
122       Result.Reference.all (1)           := Left;
123       Result.Reference.all (2 .. Length) := Right.Reference.all;
124       return Result;
125    end "&";
126
127    ---------
128    -- "*" --
129    ---------
130
131    function "*"
132      (Left  : Natural;
133       Right : Wide_Character)
134       return  Unbounded_Wide_String
135    is
136       Result : Unbounded_Wide_String;
137
138    begin
139       Result.Reference := new Wide_String (1 .. Left);
140       for J in Result.Reference'Range loop
141          Result.Reference (J) := Right;
142       end loop;
143
144       return Result;
145    end "*";
146
147    function "*"
148      (Left   : Natural;
149       Right  : Wide_String)
150       return   Unbounded_Wide_String
151    is
152       Result : Unbounded_Wide_String;
153
154    begin
155       Result.Reference := new Wide_String (1 .. Left * Right'Length);
156
157       for J in 1 .. Left loop
158          Result.Reference.all
159            (Right'Length * J - Right'Length + 1 .. Right'Length * J) := Right;
160       end loop;
161
162       return Result;
163    end "*";
164
165    function "*"
166      (Left  : Natural;
167       Right : Unbounded_Wide_String)
168       return  Unbounded_Wide_String
169    is
170       R_Length : constant Integer := Right.Reference.all'Length;
171       Result   : Unbounded_Wide_String;
172
173    begin
174       Result.Reference := new Wide_String (1 .. Left * R_Length);
175
176       for I in 1 .. Left loop
177          Result.Reference.all (R_Length * I - R_Length + 1 .. R_Length * I) :=
178            Right.Reference.all;
179       end loop;
180
181       return Result;
182    end "*";
183
184    ---------
185    -- "<" --
186    ---------
187
188    function "<"
189      (Left  : in Unbounded_Wide_String;
190       Right : in Unbounded_Wide_String)
191       return  Boolean
192    is
193    begin
194       return Left.Reference.all < Right.Reference.all;
195    end "<";
196
197    function "<"
198      (Left  : in Unbounded_Wide_String;
199       Right : in Wide_String)
200       return  Boolean
201    is
202    begin
203       return Left.Reference.all < Right;
204    end "<";
205
206    function "<"
207      (Left  : in Wide_String;
208       Right : in Unbounded_Wide_String)
209       return  Boolean
210    is
211    begin
212       return Left < Right.Reference.all;
213    end "<";
214
215    ----------
216    -- "<=" --
217    ----------
218
219    function "<="
220      (Left  : in Unbounded_Wide_String;
221       Right : in Unbounded_Wide_String)
222       return  Boolean
223    is
224    begin
225       return Left.Reference.all <= Right.Reference.all;
226    end "<=";
227
228    function "<="
229      (Left  : in Unbounded_Wide_String;
230       Right : in Wide_String)
231       return  Boolean
232    is
233    begin
234       return Left.Reference.all <= Right;
235    end "<=";
236
237    function "<="
238      (Left  : in Wide_String;
239       Right : in Unbounded_Wide_String)
240       return  Boolean
241    is
242    begin
243       return Left <= Right.Reference.all;
244    end "<=";
245
246    ---------
247    -- "=" --
248    ---------
249
250    function "="
251      (Left  : in Unbounded_Wide_String;
252       Right : in Unbounded_Wide_String)
253       return  Boolean
254    is
255    begin
256       return Left.Reference.all = Right.Reference.all;
257    end "=";
258
259    function "="
260      (Left  : in Unbounded_Wide_String;
261       Right : in Wide_String)
262       return  Boolean
263    is
264    begin
265       return Left.Reference.all = Right;
266    end "=";
267
268    function "="
269      (Left  : in Wide_String;
270       Right : in Unbounded_Wide_String)
271       return  Boolean
272    is
273    begin
274       return Left = Right.Reference.all;
275    end "=";
276
277    ---------
278    -- ">" --
279    ---------
280
281    function ">"
282      (Left  : in Unbounded_Wide_String;
283       Right : in Unbounded_Wide_String)
284       return  Boolean
285    is
286    begin
287       return Left.Reference.all > Right.Reference.all;
288    end ">";
289
290    function ">"
291      (Left  : in Unbounded_Wide_String;
292       Right : in Wide_String)
293       return  Boolean
294    is
295    begin
296       return Left.Reference.all > Right;
297    end ">";
298
299    function ">"
300      (Left  : in Wide_String;
301       Right : in Unbounded_Wide_String)
302       return  Boolean
303    is
304    begin
305       return Left > Right.Reference.all;
306    end ">";
307
308    ----------
309    -- ">=" --
310    ----------
311
312    function ">="
313      (Left  : in Unbounded_Wide_String;
314       Right : in Unbounded_Wide_String)
315       return  Boolean
316    is
317    begin
318       return Left.Reference.all >= Right.Reference.all;
319    end ">=";
320
321    function ">="
322      (Left  : in Unbounded_Wide_String;
323       Right : in Wide_String)
324       return  Boolean
325    is
326    begin
327       return Left.Reference.all >= Right;
328    end ">=";
329
330    function ">="
331      (Left  : in Wide_String;
332       Right : in Unbounded_Wide_String)
333       return  Boolean
334    is
335    begin
336       return Left >= Right.Reference.all;
337    end ">=";
338
339    ------------
340    -- Adjust --
341    ------------
342
343    procedure Adjust (Object : in out Unbounded_Wide_String) is
344    begin
345       --  Copy string, except we do not copy the statically allocated
346       --  null string, since it can never be deallocated.
347
348       if Object.Reference /= Null_Wide_String'Access then
349          Object.Reference := new Wide_String'(Object.Reference.all);
350       end if;
351    end Adjust;
352
353    ------------
354    -- Append --
355    ------------
356
357    procedure Append
358      (Source   : in out Unbounded_Wide_String;
359       New_Item : in Unbounded_Wide_String)
360    is
361       S_Length : constant Integer := Source.Reference.all'Length;
362       Length   : constant Integer := S_Length + New_Item.Reference.all'Length;
363       Temp     : Wide_String_Access := Source.Reference;
364
365    begin
366       if Source.Reference = Null_Wide_String'Access then
367          Source := To_Unbounded_Wide_String (New_Item.Reference.all);
368          return;
369       end if;
370
371       Source.Reference := new Wide_String (1 .. Length);
372
373       Source.Reference.all (1 .. S_Length) := Temp.all;
374       Source.Reference.all (S_Length + 1 .. Length) := New_Item.Reference.all;
375       Free (Temp);
376    end Append;
377
378    procedure Append
379      (Source   : in out Unbounded_Wide_String;
380       New_Item : in Wide_String)
381    is
382       S_Length : constant Integer := Source.Reference.all'Length;
383       Length   : constant Integer := S_Length + New_Item'Length;
384       Temp     : Wide_String_Access := Source.Reference;
385
386    begin
387       if Source.Reference = Null_Wide_String'Access then
388          Source := To_Unbounded_Wide_String (New_Item);
389          return;
390       end if;
391
392       Source.Reference := new Wide_String (1 .. Length);
393       Source.Reference.all (1 .. S_Length) := Temp.all;
394       Source.Reference.all (S_Length + 1 .. Length) := New_Item;
395       Free (Temp);
396    end Append;
397
398    procedure Append
399      (Source   : in out Unbounded_Wide_String;
400       New_Item : in Wide_Character)
401    is
402       S_Length : constant Integer := Source.Reference.all'Length;
403       Length   : constant Integer := S_Length + 1;
404       Temp     : Wide_String_Access := Source.Reference;
405
406    begin
407       if Source.Reference = Null_Wide_String'Access then
408          Source := To_Unbounded_Wide_String ("" & New_Item);
409          return;
410       end if;
411
412       Source.Reference := new Wide_String (1 .. Length);
413       Source.Reference.all (1 .. S_Length) := Temp.all;
414       Source.Reference.all (S_Length + 1) := New_Item;
415       Free (Temp);
416    end Append;
417
418    -----------
419    -- Count --
420    -----------
421
422    function Count
423      (Source   : Unbounded_Wide_String;
424       Pattern  : Wide_String;
425       Mapping  : Wide_Maps.Wide_Character_Mapping :=
426                         Wide_Maps.Identity)
427       return     Natural
428    is
429    begin
430       return Wide_Search.Count (Source.Reference.all, Pattern, Mapping);
431    end Count;
432
433    function Count
434      (Source   : in Unbounded_Wide_String;
435       Pattern  : in Wide_String;
436       Mapping  : in Wide_Maps.Wide_Character_Mapping_Function)
437       return     Natural
438    is
439    begin
440       return Wide_Search.Count (Source.Reference.all, Pattern, Mapping);
441    end Count;
442
443    function Count
444      (Source   : Unbounded_Wide_String;
445       Set      : Wide_Maps.Wide_Character_Set)
446       return     Natural
447    is
448    begin
449       return Wide_Search.Count (Source.Reference.all, Set);
450    end Count;
451
452    ------------
453    -- Delete --
454    ------------
455
456    function Delete
457      (Source  : Unbounded_Wide_String;
458       From    : Positive;
459       Through : Natural)
460       return    Unbounded_Wide_String
461    is
462    begin
463       return
464         To_Unbounded_Wide_String
465           (Wide_Fixed.Delete (Source.Reference.all, From, Through));
466    end Delete;
467
468    procedure Delete
469      (Source  : in out Unbounded_Wide_String;
470       From    : in Positive;
471       Through : in Natural)
472    is
473       Temp : Wide_String_Access := Source.Reference;
474    begin
475       Source := To_Unbounded_Wide_String
476         (Wide_Fixed.Delete (Temp.all, From, Through));
477    end Delete;
478
479    -------------
480    -- Element --
481    -------------
482
483    function Element
484      (Source : Unbounded_Wide_String;
485       Index  : Positive)
486       return   Wide_Character
487    is
488    begin
489       if Index <= Source.Reference.all'Last then
490          return Source.Reference.all (Index);
491       else
492          raise Strings.Index_Error;
493       end if;
494    end Element;
495
496    --------------
497    -- Finalize --
498    --------------
499
500    procedure Finalize (Object : in out Unbounded_Wide_String) is
501       procedure Deallocate is
502         new Ada.Unchecked_Deallocation (Wide_String, Wide_String_Access);
503
504    begin
505       --  Note: Don't try to free statically allocated null string
506
507       if Object.Reference /= Null_Wide_String'Access then
508          Deallocate (Object.Reference);
509          Object.Reference := Null_Unbounded_Wide_String.Reference;
510       end if;
511    end Finalize;
512
513    ----------------
514    -- Find_Token --
515    ----------------
516
517    procedure Find_Token
518      (Source : Unbounded_Wide_String;
519       Set    : Wide_Maps.Wide_Character_Set;
520       Test   : Strings.Membership;
521       First  : out Positive;
522       Last   : out Natural)
523    is
524    begin
525       Wide_Search.Find_Token (Source.Reference.all, Set, Test, First, Last);
526    end Find_Token;
527
528    ----------
529    -- Free --
530    ----------
531
532    procedure Free (X : in out Wide_String_Access) is
533       procedure Deallocate is
534          new Ada.Unchecked_Deallocation (Wide_String, Wide_String_Access);
535    begin
536       Deallocate (X);
537    end Free;
538
539    ----------
540    -- Head --
541    ----------
542
543    function Head
544      (Source : Unbounded_Wide_String;
545       Count  : Natural;
546       Pad    : Wide_Character := Wide_Space)
547       return   Unbounded_Wide_String
548    is
549    begin
550       return
551         To_Unbounded_Wide_String
552           (Wide_Fixed.Head (Source.Reference.all, Count, Pad));
553    end Head;
554
555    procedure Head
556      (Source : in out Unbounded_Wide_String;
557       Count  : in Natural;
558       Pad    : in Wide_Character := Wide_Space)
559    is
560    begin
561       Source := To_Unbounded_Wide_String
562         (Wide_Fixed.Head (Source.Reference.all, Count, Pad));
563    end Head;
564
565    -----------
566    -- Index --
567    -----------
568
569    function Index
570      (Source   : Unbounded_Wide_String;
571       Pattern  : Wide_String;
572       Going    : Strings.Direction := Strings.Forward;
573       Mapping  : Wide_Maps.Wide_Character_Mapping :=
574                         Wide_Maps.Identity)
575       return     Natural
576    is
577    begin
578       return
579         Wide_Search.Index (Source.Reference.all, Pattern, Going, Mapping);
580    end Index;
581
582    function Index
583      (Source   : in Unbounded_Wide_String;
584       Pattern  : in Wide_String;
585       Going    : in Direction := Forward;
586       Mapping  : in Wide_Maps.Wide_Character_Mapping_Function)
587       return Natural
588    is
589    begin
590       return
591         Wide_Search.Index (Source.Reference.all, Pattern, Going, Mapping);
592    end Index;
593
594    function Index
595      (Source : Unbounded_Wide_String;
596       Set    : Wide_Maps.Wide_Character_Set;
597       Test   : Strings.Membership := Strings.Inside;
598       Going  : Strings.Direction  := Strings.Forward)
599       return   Natural
600    is
601    begin
602       return Wide_Search.Index (Source.Reference.all, Set, Test, Going);
603    end Index;
604
605    function Index_Non_Blank
606      (Source : Unbounded_Wide_String;
607       Going  : Strings.Direction := Strings.Forward)
608       return   Natural
609    is
610    begin
611       return Wide_Search.Index_Non_Blank (Source.Reference.all, Going);
612    end Index_Non_Blank;
613
614    ----------------
615    -- Initialize --
616    ----------------
617
618    procedure Initialize (Object : in out Unbounded_Wide_String) is
619    begin
620       Object.Reference := Null_Unbounded_Wide_String.Reference;
621    end Initialize;
622
623    ------------
624    -- Insert --
625    ------------
626
627    function Insert
628      (Source   : Unbounded_Wide_String;
629       Before   : Positive;
630       New_Item : Wide_String)
631       return     Unbounded_Wide_String
632    is
633    begin
634       return
635         To_Unbounded_Wide_String
636           (Wide_Fixed.Insert (Source.Reference.all, Before, New_Item));
637    end Insert;
638
639    procedure Insert
640      (Source   : in out Unbounded_Wide_String;
641       Before   : in Positive;
642       New_Item : in Wide_String)
643    is
644    begin
645       Source := To_Unbounded_Wide_String
646         (Wide_Fixed.Insert (Source.Reference.all, Before, New_Item));
647    end Insert;
648
649    ------------
650    -- Length --
651    ------------
652
653    function Length (Source : Unbounded_Wide_String) return Natural is
654    begin
655       return Source.Reference.all'Length;
656    end Length;
657
658    ---------------
659    -- Overwrite --
660    ---------------
661
662    function Overwrite
663      (Source    : Unbounded_Wide_String;
664       Position  : Positive;
665       New_Item  : Wide_String)
666       return      Unbounded_Wide_String is
667
668    begin
669       return To_Unbounded_Wide_String
670         (Wide_Fixed.Overwrite (Source.Reference.all, Position, New_Item));
671    end Overwrite;
672
673    procedure Overwrite
674      (Source    : in out Unbounded_Wide_String;
675       Position  : in Positive;
676       New_Item  : in Wide_String)
677    is
678       Temp : Wide_String_Access := Source.Reference;
679    begin
680       Source := To_Unbounded_Wide_String
681         (Wide_Fixed.Overwrite (Temp.all, Position, New_Item));
682    end Overwrite;
683
684    ---------------------
685    -- Replace_Element --
686    ---------------------
687
688    procedure Replace_Element
689      (Source : in out Unbounded_Wide_String;
690       Index  : Positive;
691       By     : Wide_Character)
692    is
693    begin
694       if Index <= Source.Reference.all'Last then
695          Source.Reference.all (Index) := By;
696       else
697          raise Strings.Index_Error;
698       end if;
699    end Replace_Element;
700
701    -------------------
702    -- Replace_Slice --
703    -------------------
704
705    function Replace_Slice
706      (Source   : Unbounded_Wide_String;
707       Low      : Positive;
708       High     : Natural;
709       By       : Wide_String)
710       return     Unbounded_Wide_String
711    is
712    begin
713       return
714         To_Unbounded_Wide_String
715           (Wide_Fixed.Replace_Slice (Source.Reference.all, Low, High, By));
716    end Replace_Slice;
717
718    procedure Replace_Slice
719      (Source   : in out Unbounded_Wide_String;
720       Low      : in Positive;
721       High     : in Natural;
722       By       : in Wide_String)
723    is
724       Temp : Wide_String_Access := Source.Reference;
725    begin
726       Source := To_Unbounded_Wide_String
727         (Wide_Fixed.Replace_Slice (Temp.all, Low, High, By));
728    end Replace_Slice;
729
730    -----------
731    -- Slice --
732    -----------
733
734    function Slice
735      (Source : Unbounded_Wide_String;
736       Low    : Positive;
737       High   : Natural)
738       return   Wide_String
739    is
740       Length : constant Natural := Source.Reference'Length;
741
742    begin
743       --  Note: test of High > Length is in accordance with AI95-00128
744
745       if Low > Length + 1 or else High > Length then
746          raise Index_Error;
747
748       else
749          declare
750             Result : Wide_String (1 .. High - Low + 1);
751
752          begin
753             Result := Source.Reference.all (Low .. High);
754             return Result;
755          end;
756       end if;
757    end Slice;
758
759    ----------
760    -- Tail --
761    ----------
762
763    function Tail
764      (Source : Unbounded_Wide_String;
765       Count  : Natural;
766       Pad    : Wide_Character := Wide_Space)
767       return   Unbounded_Wide_String is
768
769    begin
770       return
771         To_Unbounded_Wide_String
772           (Wide_Fixed.Tail (Source.Reference.all, Count, Pad));
773    end Tail;
774
775    procedure Tail
776      (Source : in out Unbounded_Wide_String;
777       Count  : in Natural;
778       Pad    : in Wide_Character := Wide_Space)
779    is
780       Temp : Wide_String_Access := Source.Reference;
781
782    begin
783       Source := To_Unbounded_Wide_String
784         (Wide_Fixed.Tail (Temp.all, Count, Pad));
785    end Tail;
786
787    ------------------------------
788    -- To_Unbounded_Wide_String --
789    ------------------------------
790
791    function To_Unbounded_Wide_String
792      (Source : Wide_String)
793       return   Unbounded_Wide_String
794    is
795       Result : Unbounded_Wide_String;
796
797    begin
798       Result.Reference := new Wide_String (1 .. Source'Length);
799       Result.Reference.all := Source;
800       return Result;
801    end To_Unbounded_Wide_String;
802
803    function To_Unbounded_Wide_String (Length : in Natural)
804       return Unbounded_Wide_String
805    is
806       Result : Unbounded_Wide_String;
807
808    begin
809       Result.Reference := new Wide_String (1 .. Length);
810       return Result;
811    end To_Unbounded_Wide_String;
812
813    --------------------
814    -- To_Wide_String --
815    --------------------
816
817    function To_Wide_String
818      (Source : Unbounded_Wide_String)
819       return   Wide_String
820    is
821    begin
822       return Source.Reference.all;
823    end To_Wide_String;
824
825    ---------------
826    -- Translate --
827    ---------------
828
829    function Translate
830      (Source  : Unbounded_Wide_String;
831       Mapping : Wide_Maps.Wide_Character_Mapping)
832       return    Unbounded_Wide_String
833    is
834    begin
835       return
836         To_Unbounded_Wide_String
837           (Wide_Fixed.Translate (Source.Reference.all, Mapping));
838    end Translate;
839
840    procedure Translate
841      (Source  : in out Unbounded_Wide_String;
842       Mapping : Wide_Maps.Wide_Character_Mapping)
843    is
844    begin
845       Wide_Fixed.Translate (Source.Reference.all, Mapping);
846    end Translate;
847
848    function Translate
849      (Source  : in Unbounded_Wide_String;
850       Mapping : in Wide_Maps.Wide_Character_Mapping_Function)
851       return    Unbounded_Wide_String
852    is
853    begin
854       return
855         To_Unbounded_Wide_String
856           (Wide_Fixed.Translate (Source.Reference.all, Mapping));
857    end Translate;
858
859    procedure Translate
860      (Source  : in out Unbounded_Wide_String;
861       Mapping : in Wide_Maps.Wide_Character_Mapping_Function)
862    is
863    begin
864       Wide_Fixed.Translate (Source.Reference.all, Mapping);
865    end Translate;
866
867    ----------
868    -- Trim --
869    ----------
870
871    function Trim
872      (Source : in Unbounded_Wide_String;
873       Side   : in Trim_End)
874       return   Unbounded_Wide_String
875    is
876    begin
877       return
878         To_Unbounded_Wide_String
879           (Wide_Fixed.Trim (Source.Reference.all, Side));
880    end Trim;
881
882    procedure Trim
883      (Source : in out Unbounded_Wide_String;
884       Side   : in Trim_End)
885    is
886       Old : Wide_String_Access := Source.Reference;
887    begin
888       Source.Reference := new Wide_String'(Wide_Fixed.Trim (Old.all, Side));
889       Free (Old);
890    end Trim;
891
892    function Trim
893      (Source : in Unbounded_Wide_String;
894       Left   : in Wide_Maps.Wide_Character_Set;
895       Right  : in Wide_Maps.Wide_Character_Set)
896       return   Unbounded_Wide_String
897    is
898    begin
899       return
900         To_Unbounded_Wide_String
901           (Wide_Fixed.Trim (Source.Reference.all, Left, Right));
902    end Trim;
903
904    procedure Trim
905      (Source : in out Unbounded_Wide_String;
906       Left   : in Wide_Maps.Wide_Character_Set;
907       Right  : in Wide_Maps.Wide_Character_Set)
908    is
909       Old : Wide_String_Access := Source.Reference;
910
911    begin
912       Source.Reference :=
913         new Wide_String'(Wide_Fixed.Trim (Old.all, Left, Right));
914       Free (Old);
915    end Trim;
916
917 end Ada.Strings.Wide_Unbounded;