------------------------------------------------------------------------------
-- --
--- GNAT RUNTIME COMPONENTS --
+-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . S T R I N G S . S U P E R B O U N D E D --
-- --
-- B o d y --
-- --
--- Copyright (C) 2003 Free Software Foundation, Inc. --
+-- Copyright (C) 2003-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, --
function Concat
(Left : Super_String;
- Right : Super_String)
- return Super_String
+ Right : Super_String) return Super_String
is
Result : Super_String (Left.Max_Length);
Llen : constant Natural := Left.Current_Length;
function Concat
(Left : Super_String;
- Right : String)
- return Super_String
+ Right : String) return Super_String
is
Result : Super_String (Left.Max_Length);
Llen : constant Natural := Left.Current_Length;
function Concat
(Left : String;
- Right : Super_String)
- return Super_String
+ Right : Super_String) return Super_String
is
Result : Super_String (Right.Max_Length);
Llen : constant Natural := Left'Length;
function Concat
(Left : Super_String;
- Right : Character)
- return Super_String
+ Right : Character) return Super_String
is
Result : Super_String (Left.Max_Length);
Llen : constant Natural := Left.Current_Length;
function Concat
(Left : Character;
- Right : Super_String)
- return Super_String
+ Right : Super_String) return Super_String
is
Result : Super_String (Right.Max_Length);
Rlen : constant Natural := Right.Current_Length;
-- Equal --
-----------
- function "=" (Left, Right : Super_String) return Boolean is
+ function "="
+ (Left : Super_String;
+ Right : Super_String) return Boolean
+ is
begin
return Left.Current_Length = Right.Current_Length
and then Left.Data (1 .. Left.Current_Length) =
Right.Data (1 .. Right.Current_Length);
end "=";
- function Equal (Left : Super_String; Right : String)
- return Boolean is
+ function Equal
+ (Left : Super_String;
+ Right : String) return Boolean
+ is
begin
return Left.Current_Length = Right'Length
and then Left.Data (1 .. Left.Current_Length) = Right;
end Equal;
- function Equal (Left : String; Right : Super_String)
- return Boolean is
+ function Equal
+ (Left : String;
+ Right : Super_String) return Boolean
+ is
begin
return Left'Length = Right.Current_Length
and then Left = Right.Data (1 .. Right.Current_Length);
-- Greater --
-------------
- function Greater (Left, Right : Super_String) return Boolean is
+ function Greater
+ (Left : Super_String;
+ Right : Super_String) return Boolean
+ is
begin
return Left.Data (1 .. Left.Current_Length) >
Right.Data (1 .. Right.Current_Length);
function Greater
(Left : Super_String;
- Right : String)
- return Boolean
+ Right : String) return Boolean
is
begin
return Left.Data (1 .. Left.Current_Length) > Right;
function Greater
(Left : String;
- Right : Super_String)
- return Boolean
+ Right : Super_String) return Boolean
is
begin
return Left > Right.Data (1 .. Right.Current_Length);
-- Greater_Or_Equal --
----------------------
- function Greater_Or_Equal (Left, Right : Super_String) return Boolean is
+ function Greater_Or_Equal
+ (Left : Super_String;
+ Right : Super_String) return Boolean
+ is
begin
return Left.Data (1 .. Left.Current_Length) >=
Right.Data (1 .. Right.Current_Length);
function Greater_Or_Equal
(Left : Super_String;
- Right : String)
- return Boolean
+ Right : String) return Boolean
is
begin
return Left.Data (1 .. Left.Current_Length) >= Right;
function Greater_Or_Equal
(Left : String;
- Right : Super_String)
- return Boolean
+ Right : Super_String) return Boolean
is
begin
return Left >= Right.Data (1 .. Right.Current_Length);
-- Less --
----------
- function Less (Left, Right : Super_String) return Boolean is
+ function Less
+ (Left : Super_String;
+ Right : Super_String) return Boolean
+ is
begin
return Left.Data (1 .. Left.Current_Length) <
Right.Data (1 .. Right.Current_Length);
function Less
(Left : Super_String;
- Right : String)
- return Boolean
+ Right : String) return Boolean
is
begin
return Left.Data (1 .. Left.Current_Length) < Right;
function Less
(Left : String;
- Right : Super_String)
- return Boolean
+ Right : Super_String) return Boolean
is
begin
return Left < Right.Data (1 .. Right.Current_Length);
-- Less_Or_Equal --
-------------------
- function Less_Or_Equal (Left, Right : Super_String) return Boolean is
+ function Less_Or_Equal
+ (Left : Super_String;
+ Right : Super_String) return Boolean
+ is
begin
return Left.Data (1 .. Left.Current_Length) <=
Right.Data (1 .. Right.Current_Length);
function Less_Or_Equal
(Left : Super_String;
- Right : String)
- return Boolean
+ Right : String) return Boolean
is
begin
return Left.Data (1 .. Left.Current_Length) <= Right;
function Less_Or_Equal
(Left : String;
- Right : Super_String)
- return Boolean
+ Right : Super_String) return Boolean
is
begin
return Left <= Right.Data (1 .. Right.Current_Length);
end Less_Or_Equal;
+ ----------------------
+ -- Set_Super_String --
+ ----------------------
+
+ procedure Set_Super_String
+ (Target : out Super_String;
+ Source : String;
+ Drop : Truncation := Error)
+ is
+ Slen : constant Natural := Source'Length;
+ Max_Length : constant Positive := Target.Max_Length;
+
+ begin
+ if Slen <= Max_Length then
+ Target.Current_Length := Slen;
+ Target.Data (1 .. Slen) := Source;
+
+ else
+ case Drop is
+ when Strings.Right =>
+ Target.Current_Length := Max_Length;
+ Target.Data (1 .. Max_Length) :=
+ Source (Source'First .. Source'First - 1 + Max_Length);
+
+ when Strings.Left =>
+ Target.Current_Length := Max_Length;
+ Target.Data (1 .. Max_Length) :=
+ Source (Source'Last - (Max_Length - 1) .. Source'Last);
+
+ when Strings.Error =>
+ raise Ada.Strings.Length_Error;
+ end case;
+ end if;
+ end Set_Super_String;
+
------------------
-- Super_Append --
------------------
-- Case of Super_String and Super_String
function Super_Append
- (Left, Right : Super_String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ (Left : Super_String;
+ Right : Super_String;
+ Drop : Truncation := Error) return Super_String
is
Max_Length : constant Positive := Left.Max_Length;
Result : Super_String (Max_Length);
procedure Super_Append
(Source : in out Super_String;
New_Item : Super_String;
- Drop : Truncation := Error)
+ Drop : Truncation := Error)
is
Max_Length : constant Positive := Source.Max_Length;
Llen : constant Natural := Source.Current_Length;
function Super_Append
(Left : Super_String;
Right : String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Left.Max_Length;
Result : Super_String (Max_Length);
procedure Super_Append
(Source : in out Super_String;
New_Item : String;
- Drop : Truncation := Error)
+ Drop : Truncation := Error)
is
Max_Length : constant Positive := Source.Max_Length;
Llen : constant Natural := Source.Current_Length;
function Super_Append
(Left : String;
Right : Super_String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Right.Max_Length;
Result : Super_String (Max_Length);
function Super_Append
(Left : Super_String;
Right : Character;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Left.Max_Length;
Result : Super_String (Max_Length);
procedure Super_Append
(Source : in out Super_String;
New_Item : Character;
- Drop : Truncation := Error)
+ Drop : Truncation := Error)
is
Max_Length : constant Positive := Source.Max_Length;
Llen : constant Natural := Source.Current_Length;
function Super_Append
(Left : Character;
Right : Super_String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Right.Max_Length;
Result : Super_String (Max_Length);
-----------------
function Super_Count
- (Source : Super_String;
- Pattern : String;
- Mapping : Maps.Character_Mapping := Maps.Identity)
- return Natural
+ (Source : Super_String;
+ Pattern : String;
+ Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
is
begin
return
end Super_Count;
function Super_Count
- (Source : Super_String;
- Pattern : String;
- Mapping : Maps.Character_Mapping_Function)
- return Natural
+ (Source : Super_String;
+ Pattern : String;
+ Mapping : Maps.Character_Mapping_Function) return Natural
is
begin
return
function Super_Count
(Source : Super_String;
- Set : Maps.Character_Set)
- return Natural
+ Set : Maps.Character_Set) return Natural
is
begin
return Search.Count (Source.Data (1 .. Source.Current_Length), Set);
function Super_Delete
(Source : Super_String;
From : Positive;
- Through : Natural)
- return Super_String
+ Through : Natural) return Super_String
is
Result : Super_String (Source.Max_Length);
Slen : constant Natural := Source.Current_Length;
function Super_Element
(Source : Super_String;
- Index : Positive)
- return Character
+ Index : Positive) return Character
is
begin
if Index in 1 .. Source.Current_Length then
(Source : Super_String;
Count : Natural;
Pad : Character := Space;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Source.Max_Length;
Result : Super_String (Max_Length);
procedure Super_Head
(Source : in out Super_String;
Count : Natural;
- Pad : Character := Space;
+ Pad : Character := Space;
Drop : Truncation := Error)
is
Max_Length : constant Positive := Source.Max_Length;
-----------------
function Super_Index
- (Source : Super_String;
- Pattern : String;
- Going : Strings.Direction := Strings.Forward;
- Mapping : Maps.Character_Mapping := Maps.Identity)
- return Natural
+ (Source : Super_String;
+ Pattern : String;
+ Going : Strings.Direction := Strings.Forward;
+ Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
is
begin
return Search.Index
end Super_Index;
function Super_Index
- (Source : Super_String;
- Pattern : String;
- Going : Direction := Forward;
- Mapping : Maps.Character_Mapping_Function)
- return Natural
+ (Source : Super_String;
+ Pattern : String;
+ Going : Direction := Forward;
+ Mapping : Maps.Character_Mapping_Function) return Natural
is
begin
return Search.Index
(Source : Super_String;
Set : Maps.Character_Set;
Test : Strings.Membership := Strings.Inside;
- Going : Strings.Direction := Strings.Forward)
- return Natural
+ Going : Strings.Direction := Strings.Forward) return Natural
is
begin
return Search.Index
(Source.Data (1 .. Source.Current_Length), Set, Test, Going);
end Super_Index;
+ function Super_Index
+ (Source : Super_String;
+ Pattern : String;
+ From : Positive;
+ Going : Direction := Forward;
+ Mapping : Maps.Character_Mapping := Maps.Identity) return Natural
+ is
+ begin
+ return Search.Index
+ (Source.Data (1 .. Source.Current_Length),
+ Pattern, From, Going, Mapping);
+ end Super_Index;
+
+ function Super_Index
+ (Source : Super_String;
+ Pattern : String;
+ From : Positive;
+ Going : Direction := Forward;
+ Mapping : Maps.Character_Mapping_Function) return Natural
+ is
+ begin
+ return Search.Index
+ (Source.Data (1 .. Source.Current_Length),
+ Pattern, From, Going, Mapping);
+ end Super_Index;
+
+ function Super_Index
+ (Source : Super_String;
+ Set : Maps.Character_Set;
+ From : Positive;
+ Test : Membership := Inside;
+ Going : Direction := Forward) return Natural
+ is
+ begin
+ return Search.Index
+ (Source.Data (1 .. Source.Current_Length), Set, From, Test, Going);
+ end Super_Index;
+
---------------------------
-- Super_Index_Non_Blank --
---------------------------
function Super_Index_Non_Blank
(Source : Super_String;
- Going : Strings.Direction := Strings.Forward)
- return Natural
+ Going : Strings.Direction := Strings.Forward) return Natural
is
begin
return
(Source.Data (1 .. Source.Current_Length), Going);
end Super_Index_Non_Blank;
+ function Super_Index_Non_Blank
+ (Source : Super_String;
+ From : Positive;
+ Going : Direction := Forward) return Natural
+ is
+ begin
+ return
+ Search.Index_Non_Blank
+ (Source.Data (1 .. Source.Current_Length), From, Going);
+ end Super_Index_Non_Blank;
+
------------------
-- Super_Insert --
------------------
(Source : Super_String;
Before : Positive;
New_Item : String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Source.Max_Length;
Result : Super_String (Max_Length);
---------------------
function Super_Overwrite
- (Source : Super_String;
- Position : Positive;
- New_Item : String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ (Source : Super_String;
+ Position : Positive;
+ New_Item : String;
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Source.Max_Length;
Result : Super_String (Max_Length);
-------------------------
function Super_Replace_Slice
- (Source : Super_String;
- Low : Positive;
- High : Natural;
- By : String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ (Source : Super_String;
+ Low : Positive;
+ High : Natural;
+ By : String;
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Source.Max_Length;
Slen : constant Natural := Source.Current_Length;
(Count : Natural;
Item : Character;
Drop : Truncation := Error;
- Max_Length : Positive)
- return Super_String
+ Max_Length : Positive) return Super_String
is
Result : Super_String (Max_Length);
(Count : Natural;
Item : String;
Drop : Truncation := Error;
- Max_Length : Positive)
- return Super_String
+ Max_Length : Positive) return Super_String
is
Length : constant Integer := Count * Item'Length;
Result : Super_String (Max_Length);
function Super_Replicate
(Count : Natural;
Item : Super_String;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
begin
return
function Super_Slice
(Source : Super_String;
Low : Positive;
- High : Natural)
- return String
+ High : Natural) return String
is
begin
-- Note: test of High > Length is in accordance with AI95-00128
end if;
end Super_Slice;
+ function Super_Slice
+ (Source : Super_String;
+ Low : Positive;
+ High : Natural) return Super_String
+ is
+ Result : Super_String (Source.Max_Length);
+
+ begin
+ if Low > Source.Current_Length + 1
+ or else High > Source.Current_Length
+ then
+ raise Index_Error;
+ else
+ Result.Current_Length := High - Low + 1;
+ Result.Data (1 .. Result.Current_Length) := Source.Data (Low .. High);
+ end if;
+
+ return Result;
+ end Super_Slice;
+
+ procedure Super_Slice
+ (Source : Super_String;
+ Target : out Super_String;
+ Low : Positive;
+ High : Natural)
+ is
+ begin
+ if Low > Source.Current_Length + 1
+ or else High > Source.Current_Length
+ then
+ raise Index_Error;
+ else
+ Target.Current_Length := High - Low + 1;
+ Target.Data (1 .. Target.Current_Length) := Source.Data (Low .. High);
+ end if;
+ end Super_Slice;
+
----------------
-- Super_Tail --
----------------
(Source : Super_String;
Count : Natural;
Pad : Character := Space;
- Drop : Strings.Truncation := Strings.Error)
- return Super_String
+ Drop : Strings.Truncation := Strings.Error) return Super_String
is
Max_Length : constant Positive := Source.Max_Length;
Result : Super_String (Max_Length);
procedure Super_Tail
(Source : in out Super_String;
Count : Natural;
- Pad : Character := Space;
+ Pad : Character := Space;
Drop : Truncation := Error)
is
Max_Length : constant Positive := Source.Max_Length;
-- Super_To_String --
---------------------
- function Super_To_String (Source : in Super_String) return String is
+ function Super_To_String (Source : Super_String) return String is
begin
return Source.Data (1 .. Source.Current_Length);
end Super_To_String;
function Super_Translate
(Source : Super_String;
- Mapping : Maps.Character_Mapping)
- return Super_String
+ Mapping : Maps.Character_Mapping) return Super_String
is
Result : Super_String (Source.Max_Length);
function Super_Translate
(Source : Super_String;
- Mapping : Maps.Character_Mapping_Function)
- return Super_String
+ Mapping : Maps.Character_Mapping_Function) return Super_String
is
Result : Super_String (Source.Max_Length);
-- Super_Trim --
----------------
- function Super_Trim (Source : Super_String; Side : Trim_End)
- return Super_String
+ function Super_Trim
+ (Source : Super_String;
+ Side : Trim_End) return Super_String
is
Result : Super_String (Source.Max_Length);
Last : Natural := Source.Current_Length;
function Super_Trim
(Source : Super_String;
Left : Maps.Character_Set;
- Right : Maps.Character_Set)
- return Super_String
+ Right : Maps.Character_Set) return Super_String
is
Result : Super_String (Source.Max_Length);
function Times
(Left : Natural;
Right : Character;
- Max_Length : Positive)
- return Super_String
+ Max_Length : Positive) return Super_String
is
Result : Super_String (Max_Length);
function Times
(Left : Natural;
Right : String;
- Max_Length : Positive)
- return Super_String
+ Max_Length : Positive) return Super_String
is
Result : Super_String (Max_Length);
Pos : Positive := 1;
function Times
(Left : Natural;
- Right : Super_String)
- return Super_String
+ Right : Super_String) return Super_String
is
Result : Super_String (Right.Max_Length);
Pos : Positive := 1;
function To_Super_String
(Source : String;
Max_Length : Natural;
- Drop : Truncation := Error)
- return Super_String
+ Drop : Truncation := Error) return Super_String
is
Result : Super_String (Max_Length);
Slen : constant Natural := Source'Length;