OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-strfix.adb
index 3cdb806..0f33958 100644 (file)
@@ -1,45 +1,42 @@
 ------------------------------------------------------------------------------
 --                                                                          --
---                         GNAT RUNTIME COMPONENTS                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
 --                    A D A . S T R I N G S . F I X E D                     --
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                                                                          --
---          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
+--          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
---  Note: This code is derived from the ADAR.CSH public domain Ada 83
---  versions of the Appendix C string handling packages. One change is
---  to avoid the use of Is_In, so that we are not dependent on inlining.
---  Note that the search function implementations are to be found in the
---  auxiliary package Ada.Strings.Search. Also the Move procedure is
---  directly incorporated (ADAR used a subunit for this procedure). A
---  number of errors having to do with bounds of function return results
---  were also fixed, and use of & removed for efficiency reasons.
+--  Note: This code is derived from the ADAR.CSH public domain Ada 83 versions
+--  of the Appendix C string handling packages. One change is to avoid the use
+--  of Is_In, so that we are not dependent on inlining. Note that the search
+--  function implementations are to be found in the auxiliary package
+--  Ada.Strings.Search. Also the Move procedure is directly incorporated (ADAR
+--  used a subunit for this procedure). The number of errors having to do with
+--  bounds of function return results were also fixed, and use of & removed for
+--  efficiency reasons.
 
 with Ada.Strings.Maps; use Ada.Strings.Maps;
 with Ada.Strings.Search;
@@ -51,59 +48,91 @@ package body Ada.Strings.Fixed is
    ------------------------
 
    function Index
-     (Source   : in String;
-      Pattern  : in String;
-      Going    : in Direction := Forward;
-      Mapping  : in Maps.Character_Mapping := Maps.Identity)
-      return     Natural
+     (Source  : String;
+      Pattern : String;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
+   renames Ada.Strings.Search.Index;
+
+   function Index
+     (Source  : String;
+      Pattern : String;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping_Function) return Natural
+   renames Ada.Strings.Search.Index;
+
+   function Index
+     (Source : String;
+      Set    : Maps.Character_Set;
+      Test   : Membership := Inside;
+      Going  : Direction  := Forward) return Natural
+   renames Ada.Strings.Search.Index;
+
+   function Index
+     (Source  : String;
+      Pattern : String;
+      From    : Positive;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
    renames Ada.Strings.Search.Index;
 
    function Index
-     (Source   : in String;
-      Pattern  : in String;
-      Going    : in Direction := Forward;
-      Mapping  : in Maps.Character_Mapping_Function)
-      return     Natural
+     (Source  : String;
+      Pattern : String;
+      From    : Positive;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping_Function) return Natural
    renames Ada.Strings.Search.Index;
 
    function Index
-     (Source : in String;
-      Set    : in Maps.Character_Set;
-      Test   : in Membership := Inside;
-      Going  : in Direction  := Forward)
-      return   Natural
+     (Source  : String;
+      Set     : Maps.Character_Set;
+      From    : Positive;
+      Test    : Membership := Inside;
+      Going   : Direction := Forward) return Natural
    renames Ada.Strings.Search.Index;
 
    function Index_Non_Blank
-     (Source : in String;
-      Going  : in Direction := Forward)
-      return   Natural
+     (Source : String;
+      Going  : Direction := Forward) return Natural
+   renames Ada.Strings.Search.Index_Non_Blank;
+
+   function Index_Non_Blank
+     (Source : String;
+      From   : Positive;
+      Going  : Direction := Forward) return Natural
    renames Ada.Strings.Search.Index_Non_Blank;
 
    function Count
-     (Source   : in String;
-      Pattern  : in String;
-      Mapping  : in Maps.Character_Mapping := Maps.Identity)
-      return     Natural
+     (Source  : String;
+      Pattern : String;
+      Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
    renames Ada.Strings.Search.Count;
 
    function Count
-     (Source   : in String;
-      Pattern  : in String;
-      Mapping  : in Maps.Character_Mapping_Function)
-      return     Natural
+     (Source  : String;
+      Pattern : String;
+      Mapping : Maps.Character_Mapping_Function) return Natural
    renames Ada.Strings.Search.Count;
 
    function Count
-     (Source   : in String;
-      Set      : in Maps.Character_Set)
-      return     Natural
+     (Source : String;
+      Set    : Maps.Character_Set) return Natural
    renames Ada.Strings.Search.Count;
 
    procedure Find_Token
-     (Source : in String;
-      Set    : in Maps.Character_Set;
-      Test   : in Membership;
+     (Source : String;
+      Set    : Maps.Character_Set;
+      From   : Positive;
+      Test   : Membership;
+      First  : out Positive;
+      Last   : out Natural)
+   renames Ada.Strings.Search.Find_Token;
+
+   procedure Find_Token
+     (Source : String;
+      Set    : Maps.Character_Set;
+      Test   : Membership;
       First  : out Positive;
       Last   : out Natural)
    renames Ada.Strings.Search.Find_Token;
@@ -113,9 +142,8 @@ package body Ada.Strings.Fixed is
    ---------
 
    function "*"
-     (Left  : in Natural;
-      Right : in Character)
-      return  String
+     (Left  : Natural;
+      Right : Character) return String
    is
       Result : String (1 .. Left);
 
@@ -128,9 +156,8 @@ package body Ada.Strings.Fixed is
    end "*";
 
    function "*"
-     (Left  : in Natural;
-      Right : in String)
-      return  String
+     (Left  : Natural;
+      Right : String) return String
    is
       Result : String (1 .. Left * Right'Length);
       Ptr    : Integer := 1;
@@ -149,10 +176,9 @@ package body Ada.Strings.Fixed is
    ------------
 
    function Delete
-     (Source  : in String;
-      From    : in Positive;
-      Through : in Natural)
-      return    String
+     (Source  : String;
+      From    : Positive;
+      Through : Natural) return String
    is
    begin
       if From > Through then
@@ -186,10 +212,10 @@ package body Ada.Strings.Fixed is
 
    procedure Delete
      (Source  : in out String;
-      From    : in Positive;
-      Through : in Natural;
-      Justify : in Alignment := Left;
-      Pad     : in Character := Space)
+      From    : Positive;
+      Through : Natural;
+      Justify : Alignment := Left;
+      Pad     : Character := Space)
    is
    begin
       Move (Source  => Delete (Source, From, Through),
@@ -203,10 +229,9 @@ package body Ada.Strings.Fixed is
    ----------
 
    function Head
-     (Source : in String;
-      Count  : in Natural;
-      Pad    : in Character := Space)
-      return   String
+     (Source : String;
+      Count  : Natural;
+      Pad    : Character := Space) return String
    is
       subtype Result_Type is String (1 .. Count);
 
@@ -233,9 +258,9 @@ package body Ada.Strings.Fixed is
 
    procedure Head
      (Source  : in out String;
-      Count   : in Natural;
-      Justify : in Alignment := Left;
-      Pad     : in Character := Space)
+      Count   : Natural;
+      Justify : Alignment := Left;
+      Pad     : Character := Space)
    is
    begin
       Move (Source  => Head (Source, Count, Pad),
@@ -250,10 +275,9 @@ package body Ada.Strings.Fixed is
    ------------
 
    function Insert
-     (Source   : in String;
-      Before   : in Positive;
-      New_Item : in String)
-      return     String
+     (Source   : String;
+      Before   : Positive;
+      New_Item : String) return String
    is
       Result : String (1 .. Source'Length + New_Item'Length);
       Front  : constant Integer := Before - Source'First;
@@ -275,9 +299,9 @@ package body Ada.Strings.Fixed is
 
    procedure Insert
      (Source   : in out String;
-      Before   : in Positive;
-      New_Item : in String;
-      Drop     : in Truncation := Error)
+      Before   : Positive;
+      New_Item : String;
+      Drop     : Truncation := Error)
    is
    begin
       Move (Source => Insert (Source, Before, New_Item),
@@ -290,11 +314,11 @@ package body Ada.Strings.Fixed is
    ----------
 
    procedure Move
-     (Source  : in  String;
+     (Source  : String;
       Target  : out String;
-      Drop    : in  Truncation := Error;
-      Justify : in  Alignment  := Left;
-      Pad     : in  Character  := Space)
+      Drop    : Truncation := Error;
+      Justify : Alignment  := Left;
+      Pad     : Character  := Space)
    is
       Sfirst  : constant Integer := Source'First;
       Slast   : constant Integer := Source'Last;
@@ -399,10 +423,9 @@ package body Ada.Strings.Fixed is
    ---------------
 
    function Overwrite
-     (Source   : in String;
-      Position : in Positive;
-      New_Item : in String)
-      return     String
+     (Source   : String;
+      Position : Positive;
+      New_Item : String) return String
    is
    begin
       if Position not in Source'First .. Source'Last + 1 then
@@ -410,9 +433,10 @@ package body Ada.Strings.Fixed is
       end if;
 
       declare
-         Result_Length : Natural :=
-           Integer'Max
-             (Source'Length, Position - Source'First + New_Item'Length);
+         Result_Length : constant Natural :=
+                           Integer'Max
+                             (Source'Length,
+                              Position - Source'First + New_Item'Length);
 
          Result : String (1 .. Result_Length);
          Front  : constant Integer := Position - Source'First;
@@ -430,9 +454,9 @@ package body Ada.Strings.Fixed is
 
    procedure Overwrite
      (Source   : in out String;
-      Position : in Positive;
-      New_Item : in String;
-      Drop     : in Truncation := Right)
+      Position : Positive;
+      New_Item : String;
+      Drop     : Truncation := Right)
    is
    begin
       Move (Source => Overwrite (Source, Position, New_Item),
@@ -445,14 +469,13 @@ package body Ada.Strings.Fixed is
    -------------------
 
    function Replace_Slice
-     (Source   : in String;
-      Low      : in Positive;
-      High     : in Natural;
-      By       : in String)
-      return     String
+     (Source : String;
+      Low    : Positive;
+      High   : Natural;
+      By     : String) return String
    is
    begin
-      if Low > Source'Last + 1 or High < Source'First - 1 then
+      if Low > Source'Last + 1 or else High < Source'First - 1 then
          raise Index_Error;
       end if;
 
@@ -462,8 +485,8 @@ package body Ada.Strings.Fixed is
                           Integer'Max (0, Low - Source'First);
             --  Length of prefix of Source copied to result
 
-            Back_Len  : constant Integer :=
-                          Integer'Max (0, Source'Last - High);
+            Back_Len : constant Integer :=
+                         Integer'Max (0, Source'Last - High);
             --  Length of suffix of Source copied to result
 
             Result_Length : constant Integer :=
@@ -473,13 +496,10 @@ package body Ada.Strings.Fixed is
             Result : String (1 .. Result_Length);
 
          begin
-            Result (1 .. Front_Len) :=
-              Source (Source'First .. Low - 1);
-            Result (Front_Len + 1 .. Front_Len + By'Length) :=
-              By;
+            Result (1 .. Front_Len) := Source (Source'First .. Low - 1);
+            Result (Front_Len + 1 .. Front_Len + By'Length) := By;
             Result (Front_Len + By'Length + 1 .. Result'Length) :=
               Source (High + 1 .. Source'Last);
-
             return Result;
          end;
 
@@ -490,12 +510,12 @@ package body Ada.Strings.Fixed is
 
    procedure Replace_Slice
      (Source   : in out String;
-      Low      : in Positive;
-      High     : in Natural;
-      By       : in String;
-      Drop     : in Truncation := Error;
-      Justify  : in Alignment  := Left;
-      Pad      : in Character  := Space)
+      Low      : Positive;
+      High     : Natural;
+      By       : String;
+      Drop     : Truncation := Error;
+      Justify  : Alignment  := Left;
+      Pad      : Character  := Space)
    is
    begin
       Move (Replace_Slice (Source, Low, High, By), Source, Drop, Justify, Pad);
@@ -506,10 +526,9 @@ package body Ada.Strings.Fixed is
    ----------
 
    function Tail
-     (Source : in String;
-      Count  : in Natural;
-      Pad    : in Character := Space)
-      return   String
+     (Source : String;
+      Count  : Natural;
+      Pad    : Character := Space) return String
    is
       subtype Result_Type is String (1 .. Count);
 
@@ -536,9 +555,9 @@ package body Ada.Strings.Fixed is
 
    procedure Tail
      (Source  : in out String;
-      Count   : in Natural;
-      Justify : in Alignment := Left;
-      Pad     : in Character := Space)
+      Count   : Natural;
+      Justify : Alignment := Left;
+      Pad     : Character := Space)
    is
    begin
       Move (Source  => Tail (Source, Count, Pad),
@@ -553,9 +572,8 @@ package body Ada.Strings.Fixed is
    ---------------
 
    function Translate
-     (Source  : in String;
-      Mapping : in Maps.Character_Mapping)
-      return    String
+     (Source  : String;
+      Mapping : Maps.Character_Mapping) return String
    is
       Result : String (1 .. Source'Length);
 
@@ -569,7 +587,7 @@ package body Ada.Strings.Fixed is
 
    procedure Translate
      (Source  : in out String;
-      Mapping : in Maps.Character_Mapping)
+      Mapping : Maps.Character_Mapping)
    is
    begin
       for J in Source'Range loop
@@ -578,9 +596,8 @@ package body Ada.Strings.Fixed is
    end Translate;
 
    function Translate
-     (Source  : in String;
-      Mapping : in Maps.Character_Mapping_Function)
-      return    String
+     (Source  : String;
+      Mapping : Maps.Character_Mapping_Function) return String
    is
       Result : String (1 .. Source'Length);
       pragma Unsuppress (Access_Check);
@@ -595,7 +612,7 @@ package body Ada.Strings.Fixed is
 
    procedure Translate
      (Source  : in out String;
-      Mapping : in Maps.Character_Mapping_Function)
+      Mapping : Maps.Character_Mapping_Function)
    is
       pragma Unsuppress (Access_Check);
    begin
@@ -609,9 +626,8 @@ package body Ada.Strings.Fixed is
    ----------
 
    function Trim
-     (Source : in String;
-      Side   : in Trim_End)
-      return   String
+     (Source : String;
+      Side   : Trim_End) return String
    is
       Low, High : Integer;
 
@@ -658,9 +674,9 @@ package body Ada.Strings.Fixed is
 
    procedure Trim
      (Source  : in out String;
-      Side    : in Trim_End;
-      Justify : in Alignment := Left;
-      Pad     : in Character := Space)
+      Side    : Trim_End;
+      Justify : Alignment := Left;
+      Pad     : Character := Space)
    is
    begin
       Move (Trim (Source, Side),
@@ -670,10 +686,9 @@ package body Ada.Strings.Fixed is
    end Trim;
 
    function Trim
-     (Source : in String;
-      Left   : in Maps.Character_Set;
-      Right  : in Maps.Character_Set)
-      return   String
+     (Source : String;
+      Left   : Maps.Character_Set;
+      Right  : Maps.Character_Set) return String
    is
       High, Low : Integer;
 
@@ -705,10 +720,10 @@ package body Ada.Strings.Fixed is
 
    procedure Trim
      (Source  : in out String;
-      Left    : in Maps.Character_Set;
-      Right   : in Maps.Character_Set;
-      Justify : in Alignment := Strings.Left;
-      Pad     : in Character := Space)
+      Left    : Maps.Character_Set;
+      Right   : Maps.Character_Set;
+      Justify : Alignment := Strings.Left;
+      Pad     : Character := Space)
    is
    begin
       Move (Source  => Trim (Source, Left, Right),