------------------------------------------------------------------------------
-- --
--- GNAT RUNTIME COMPONENTS --
+-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . S T R I N G S . W I D E _ S E A R C H --
-- --
-- B o d y --
-- --
--- $Revision: 1.7 $ --
--- --
--- Copyright (C) 1992,1993,1994 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2006, 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- --
-- 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, --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
function Belongs
(Element : Wide_Character;
Set : Wide_Maps.Wide_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.
function Belongs
(Element : Wide_Character;
Set : Wide_Maps.Wide_Character_Set;
- Test : Membership)
- return Boolean is
-
+ Test : Membership) return Boolean
+ is
begin
if Test = Inside then
return Is_In (Element, Set);
-----------
function Count
- (Source : in Wide_String;
- Pattern : in Wide_String;
- Mapping : in Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
- return Natural
+ (Source : Wide_String;
+ Pattern : Wide_String;
+ Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
+ return Natural
is
N : Natural;
J : Natural;
end Count;
function Count
- (Source : in Wide_String;
- Pattern : in Wide_String;
- Mapping : in Wide_Maps.Wide_Character_Mapping_Function)
- return Natural
+ (Source : Wide_String;
+ Pattern : Wide_String;
+ Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural
is
Mapped_Source : Wide_String (Source'Range);
return Count (Mapped_Source, Pattern);
end Count;
- function Count (Source : in Wide_String;
- Set : in Wide_Maps.Wide_Character_Set)
- return Natural
+ function Count
+ (Source : Wide_String;
+ Set : Wide_Maps.Wide_Character_Set) return Natural
is
N : Natural := 0;
----------------
procedure Find_Token
- (Source : in Wide_String;
- Set : in Wide_Maps.Wide_Character_Set;
- Test : in Membership;
+ (Source : Wide_String;
+ Set : Wide_Maps.Wide_Character_Set;
+ Test : Membership;
First : out Positive;
Last : out Natural)
is
-----------
function Index
- (Source : in Wide_String;
- Pattern : in Wide_String;
- Going : in Direction := Forward;
- Mapping : in Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
- return Natural
+ (Source : Wide_String;
+ Pattern : Wide_String;
+ Going : Direction := Forward;
+ Mapping : Wide_Maps.Wide_Character_Mapping := Wide_Maps.Identity)
+ return Natural
is
begin
if Pattern = "" then
return 0;
end Index;
- -----------
- -- Index --
- -----------
-
function Index
- (Source : in Wide_String;
- Pattern : in Wide_String;
- Going : in Direction := Forward;
- Mapping : in Wide_Maps.Wide_Character_Mapping_Function)
- return Natural
+ (Source : Wide_String;
+ Pattern : Wide_String;
+ Going : Direction := Forward;
+ Mapping : Wide_Maps.Wide_Character_Mapping_Function) return Natural
is
Mapped_Source : Wide_String (Source'Range);
end Index;
function Index
- (Source : in Wide_String;
- Set : in Wide_Maps.Wide_Character_Set;
- Test : in Membership := Inside;
- Going : in Direction := Forward)
- return Natural
+ (Source : Wide_String;
+ Set : Wide_Maps.Wide_Character_Set;
+ Test : Membership := Inside;
+ Going : Direction := Forward) return Natural
is
begin
if Going = Forward then
return 0;
end Index;
+ function Index
+ (Source : Wide_String;
+ Pattern : Wide_String;
+ From : Positive;
+ Going : Direction := Forward;
+ Mapping : Wide_Maps.Wide_Character_Mapping := Wide_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 : Wide_String;
+ Pattern : Wide_String;
+ From : Positive;
+ Going : Direction := Forward;
+ Mapping : Wide_Maps.Wide_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 : Wide_String;
+ Set : Wide_Maps.Wide_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 Wide_String;
- Going : in Direction := Forward)
- return Natural
+ (Source : Wide_String;
+ Going : Direction := Forward) return Natural
is
begin
if Going = Forward then
-- Fall through if no match
return 0;
+ end Index_Non_Blank;
+ function Index_Non_Blank
+ (Source : Wide_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.Wide_Search;