OSDN Git Service

2007-04-20 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-strsea.adb
index 3a60883..322aeaa 100644 (file)
@@ -1,13 +1,12 @@
 ------------------------------------------------------------------------------
 --                                                                          --
---                         GNAT RUNTIME COMPONENTS                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
 --                   A D A . S T R I N G S . S E A R C H                    --
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                                                                          --
---   Copyright (C) 1992,1993,1994,1995,1996 Free Software Foundation, Inc.  --
+--          Copyright (C) 1992-2005, 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- --
@@ -17,8 +16,8 @@
 -- 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.                                                      --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
 --                                                                          --
 -- As a special exception,  if other files  instantiate  generics from this --
 -- unit, or you link  this unit with other files  to produce an executable, --
@@ -38,7 +37,6 @@
 --  case of identity mappings for Count and Index, and also Index_Non_Blank
 --  is specialized (rather than using the general Index routine).
 
-
 with Ada.Strings.Maps; use Ada.Strings.Maps;
 
 package body Ada.Strings.Search is
@@ -50,8 +48,7 @@ package body Ada.Strings.Search is
    function Belongs
      (Element : Character;
       Set     : Maps.Character_Set;
-      Test    : Membership)
-      return    Boolean;
+      Test    : Membership) return Boolean;
    pragma Inline (Belongs);
    --  Determines if the given element is in (Test = Inside) or not in
    --  (Test = Outside) the given character set.
@@ -63,8 +60,7 @@ package body Ada.Strings.Search is
    function Belongs
      (Element : Character;
       Set     : Maps.Character_Set;
-      Test    : Membership)
-      return    Boolean
+      Test    : Membership) return Boolean
    is
    begin
       if Test = Inside then
@@ -79,10 +75,9 @@ package body Ada.Strings.Search is
    -----------
 
    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
    is
       N : Natural;
       J : Natural;
@@ -114,10 +109,9 @@ package body Ada.Strings.Search is
    end 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
    is
       Mapped_Source : String (Source'Range);
       N             : Natural;
@@ -157,9 +151,8 @@ package body Ada.Strings.Search is
    end Count;
 
    function Count
-     (Source : in String;
-      Set    : in Maps.Character_Set)
-      return   Natural
+     (Source : String;
+      Set    : Maps.Character_Set) return Natural
    is
       N : Natural := 0;
 
@@ -178,9 +171,9 @@ package body Ada.Strings.Search is
    ----------------
 
    procedure Find_Token
-     (Source : in String;
-      Set    : in Maps.Character_Set;
-      Test   : in Membership;
+     (Source : String;
+      Set    : Maps.Character_Set;
+      Test   : Membership;
       First  : out Positive;
       Last   : out Natural)
    is
@@ -215,16 +208,14 @@ package body Ada.Strings.Search 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
    is
       Cur_Index     : Natural;
       Mapped_Source : String (Source'Range);
 
-
    begin
       if Pattern = "" then
          raise Pattern_Error;
@@ -267,11 +258,11 @@ package body Ada.Strings.Search is
       return 0;
    end Index;
 
-   function Index (Source   : in String;
-                   Pattern  : in String;
-                   Going    : in Direction := Forward;
-                   Mapping  : in Maps.Character_Mapping_Function)
-      return Natural
+   function Index
+     (Source  : String;
+      Pattern : String;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping_Function) return Natural
    is
       Mapped_Source : String (Source'Range);
       Cur_Index     : Natural;
@@ -287,7 +278,6 @@ package body Ada.Strings.Search is
 
       declare
          pragma Unsuppress (Access_Check);
-
       begin
          for J in Source'Range loop
             Mapped_Source (J) := Mapping.all (Source (J));
@@ -325,11 +315,10 @@ package body Ada.Strings.Search is
    end 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;
+      Test   : Membership := Inside;
+      Going  : Direction  := Forward) return Natural
    is
    begin
       --  Forwards case
@@ -356,14 +345,91 @@ package body Ada.Strings.Search is
       return 0;
    end Index;
 
+   function Index
+     (Source  : String;
+      Pattern : String;
+      From    : Positive;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
+   is
+   begin
+      if Going = Forward then
+         if From < Source'First then
+            raise Index_Error;
+         end if;
+
+         return
+           Index (Source (From .. Source'Last), Pattern, Forward, Mapping);
+
+      else
+         if From > Source'Last then
+            raise Index_Error;
+         end if;
+
+         return
+           Index (Source (Source'First .. From), Pattern, Backward, Mapping);
+      end if;
+   end Index;
+
+   function Index
+     (Source  : String;
+      Pattern : String;
+      From    : Positive;
+      Going   : Direction := Forward;
+      Mapping : Maps.Character_Mapping_Function) return Natural
+   is
+   begin
+      if Going = Forward then
+         if From < Source'First then
+            raise Index_Error;
+         end if;
+
+         return Index
+           (Source (From .. Source'Last), Pattern, Forward, Mapping);
+
+      else
+         if From > Source'Last then
+            raise Index_Error;
+         end if;
+
+         return Index
+           (Source (Source'First .. From), Pattern, Backward, Mapping);
+      end if;
+   end Index;
+
+   function Index
+     (Source  : String;
+      Set     : Maps.Character_Set;
+      From    : Positive;
+      Test    : Membership := Inside;
+      Going   : Direction := Forward) return Natural
+   is
+   begin
+      if Going = Forward then
+         if From < Source'First then
+            raise Index_Error;
+         end if;
+
+         return
+           Index (Source (From .. Source'Last), Set, Test, Forward);
+
+      else
+         if From > Source'Last then
+            raise Index_Error;
+         end if;
+
+         return
+           Index (Source (Source'First .. From), Set, Test, Backward);
+      end if;
+   end Index;
+
    ---------------------
    -- Index_Non_Blank --
    ---------------------
 
    function Index_Non_Blank
-     (Source : in String;
-      Going  : in Direction := Forward)
-      return   Natural
+     (Source : String;
+      Going  : Direction := Forward) return Natural
    is
    begin
       if Going = Forward then
@@ -384,7 +450,30 @@ package body Ada.Strings.Search is
       --  Fall through if no match
 
       return 0;
+   end Index_Non_Blank;
+
+   function Index_Non_Blank
+     (Source : String;
+      From   : Positive;
+      Going  : Direction := Forward) return Natural
+   is
+   begin
+      if Going = Forward then
+         if From < Source'First then
+            raise Index_Error;
+         end if;
 
+         return
+           Index_Non_Blank (Source (From .. Source'Last), Forward);
+
+      else
+         if From > Source'Last then
+            raise Index_Error;
+         end if;
+
+         return
+           Index_Non_Blank (Source (Source'First .. From), Backward);
+      end if;
    end Index_Non_Blank;
 
 end Ada.Strings.Search;