home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / a-strunb.adb < prev    next >
Text File  |  2000-07-19  |  23KB  |  889 lines

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