summaryrefslogtreecommitdiff
path: root/gcc/ada/a-strsup.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/a-strsup.adb')
-rw-r--r--gcc/ada/a-strsup.adb343
1 files changed, 221 insertions, 122 deletions
diff --git a/gcc/ada/a-strsup.adb b/gcc/ada/a-strsup.adb
index 8ae039336d9..f32398e71b0 100644
--- a/gcc/ada/a-strsup.adb
+++ b/gcc/ada/a-strsup.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2003 Free Software Foundation, Inc. --
+-- Copyright (C) 2003-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- --
@@ -42,8 +42,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -64,8 +63,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -85,8 +83,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -107,8 +104,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -127,8 +123,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -149,22 +144,29 @@ package body Ada.Strings.Superbounded is
-- 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);
@@ -174,7 +176,10 @@ package body Ada.Strings.Superbounded is
-- 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);
@@ -182,8 +187,7 @@ package body Ada.Strings.Superbounded is
function Greater
(Left : Super_String;
- Right : String)
- return Boolean
+ Right : String) return Boolean
is
begin
return Left.Data (1 .. Left.Current_Length) > Right;
@@ -191,8 +195,7 @@ package body Ada.Strings.Superbounded is
function Greater
(Left : String;
- Right : Super_String)
- return Boolean
+ Right : Super_String) return Boolean
is
begin
return Left > Right.Data (1 .. Right.Current_Length);
@@ -202,7 +205,10 @@ package body Ada.Strings.Superbounded is
-- 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);
@@ -210,8 +216,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -219,8 +224,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -230,7 +234,10 @@ package body Ada.Strings.Superbounded is
-- 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);
@@ -238,8 +245,7 @@ package body Ada.Strings.Superbounded is
function Less
(Left : Super_String;
- Right : String)
- return Boolean
+ Right : String) return Boolean
is
begin
return Left.Data (1 .. Left.Current_Length) < Right;
@@ -247,8 +253,7 @@ package body Ada.Strings.Superbounded is
function Less
(Left : String;
- Right : Super_String)
- return Boolean
+ Right : Super_String) return Boolean
is
begin
return Left < Right.Data (1 .. Right.Current_Length);
@@ -258,7 +263,10 @@ package body Ada.Strings.Superbounded is
-- 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);
@@ -266,8 +274,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -275,13 +282,47 @@ package body Ada.Strings.Superbounded is
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 --
------------------
@@ -289,9 +330,9 @@ package body Ada.Strings.Superbounded is
-- 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);
@@ -341,7 +382,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -386,8 +427,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -440,7 +480,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -488,8 +528,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -543,8 +582,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -578,7 +616,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -612,8 +650,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -649,10 +686,9 @@ package body Ada.Strings.Superbounded is
-----------------
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
@@ -661,10 +697,9 @@ package body Ada.Strings.Superbounded is
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
@@ -674,8 +709,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -688,8 +722,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -747,8 +780,7 @@ package body Ada.Strings.Superbounded is
function Super_Element
(Source : Super_String;
- Index : Positive)
- return Character
+ Index : Positive) return Character
is
begin
if Index in 1 .. Source.Current_Length then
@@ -782,8 +814,7 @@ package body Ada.Strings.Superbounded is
(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);
@@ -830,7 +861,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -878,11 +909,10 @@ package body Ada.Strings.Superbounded is
-----------------
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
@@ -890,11 +920,10 @@ package body Ada.Strings.Superbounded is
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
@@ -905,22 +934,58 @@ package body Ada.Strings.Superbounded is
(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
@@ -928,6 +993,17 @@ package body Ada.Strings.Superbounded is
(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 --
------------------
@@ -936,8 +1012,7 @@ package body Ada.Strings.Superbounded is
(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);
@@ -1032,11 +1107,10 @@ package body Ada.Strings.Superbounded is
---------------------
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);
@@ -1172,12 +1246,11 @@ package body Ada.Strings.Superbounded is
-------------------------
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;
@@ -1273,8 +1346,7 @@ package body Ada.Strings.Superbounded is
(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);
@@ -1297,8 +1369,7 @@ package body Ada.Strings.Superbounded is
(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);
@@ -1354,8 +1425,7 @@ package body Ada.Strings.Superbounded is
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
@@ -1373,8 +1443,7 @@ package body Ada.Strings.Superbounded is
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
@@ -1388,6 +1457,43 @@ package body Ada.Strings.Superbounded is
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 .. Source.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 .. Source.Current_Length) := Source.Data (Low .. High);
+ end if;
+ end Super_Slice;
+
----------------
-- Super_Tail --
----------------
@@ -1396,8 +1502,7 @@ package body Ada.Strings.Superbounded is
(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);
@@ -1445,7 +1550,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -1497,7 +1602,7 @@ package body Ada.Strings.Superbounded is
-- 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;
@@ -1508,8 +1613,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -1535,8 +1639,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -1564,8 +1667,9 @@ package body Ada.Strings.Superbounded is
-- 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;
@@ -1621,8 +1725,7 @@ package body Ada.Strings.Superbounded is
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);
@@ -1688,8 +1791,7 @@ package body Ada.Strings.Superbounded is
function Times
(Left : Natural;
Right : Character;
- Max_Length : Positive)
- return Super_String
+ Max_Length : Positive) return Super_String
is
Result : Super_String (Max_Length);
@@ -1711,8 +1813,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -1739,8 +1840,7 @@ package body Ada.Strings.Superbounded is
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;
@@ -1773,8 +1873,7 @@ package body Ada.Strings.Superbounded is
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;