diff options
author | Vincent Celier <celier@adacore.com> | 2011-08-01 10:15:08 +0000 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2011-08-01 12:15:08 +0200 |
commit | a3a16b218709b07f98329f42bc805d1c7731f71b (patch) | |
tree | 86ff1efde4c61f8e8a7fd029042f82c224172f22 /gcc/ada | |
parent | ff58cc6919e0364fddc7dc355c48246ad1e7c2e6 (diff) | |
download | gcc-a3a16b218709b07f98329f42bc805d1c7731f71b.zip gcc-a3a16b218709b07f98329f42bc805d1c7731f71b.tar.gz gcc-a3a16b218709b07f98329f42bc805d1c7731f71b.tar.bz2 |
a-stzfix.adb, [...] (Replace_Slice): Fixed computation when High is above Source length.
2011-08-01 Vincent Celier <celier@adacore.com>
* a-stzfix.adb, a-stwifi.adb (Replace_Slice): Fixed computation when
High is above Source length.
From-SVN: r177007
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/a-stwifi.adb | 38 | ||||
-rw-r--r-- | gcc/ada/a-stzfix.adb | 36 |
3 files changed, 52 insertions, 27 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index f8cebbac..e9de336 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2011-08-01 Vincent Celier <celier@adacore.com> + + * a-stzfix.adb, a-stwifi.adb (Replace_Slice): Fixed computation when + High is above Source length. + 2011-08-01 Robert Dewar <dewar@adacore.com> * a-ztexio.ads, a-textio.ads, a-witeio.ads: Fix comment. diff --git a/gcc/ada/a-stwifi.adb b/gcc/ada/a-stwifi.adb index c422906..3127850 100644 --- a/gcc/ada/a-stwifi.adb +++ b/gcc/ada/a-stwifi.adb @@ -447,30 +447,40 @@ package body Ada.Strings.Wide_Fixed is High : Natural; By : Wide_String) return Wide_String is - Result_Length : Natural; - begin if Low > Source'Last + 1 or else High < Source'First - 1 then raise Index_Error; - else - Result_Length := - Source'Length - Natural'Max (High - Low + 1, 0) + By'Length; + end if; + if High >= Low then declare - Result : Wide_String (1 .. Result_Length); + Front_Len : constant Integer := + Integer'Max (0, Low - Source'First); + -- Length of prefix of Source copied to result + + Back_Len : constant Integer := + Integer'Max (0, Source'Last - High); + -- Length of suffix of Source copied to result + + Result_Length : constant Integer := + Front_Len + By'Length + Back_Len; + -- Length of result + + Result : Wide_String (1 .. Result_Length); begin - if High >= Low then - Result := - Source (Source'First .. Low - 1) & By & - Source (High + 1 .. Source'Last); - else - Result := Source (Source'First .. Low - 1) & By & - Source (Low .. Source'Last); - end if; + 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; + + else + return Insert (Source, Before => Low, New_Item => By); end if; end Replace_Slice; diff --git a/gcc/ada/a-stzfix.adb b/gcc/ada/a-stzfix.adb index 077a65c..67f5482 100644 --- a/gcc/ada/a-stzfix.adb +++ b/gcc/ada/a-stzfix.adb @@ -449,30 +449,40 @@ package body Ada.Strings.Wide_Wide_Fixed is High : Natural; By : Wide_Wide_String) return Wide_Wide_String is - Result_Length : Natural; - begin if Low > Source'Last + 1 or else High < Source'First - 1 then raise Index_Error; - else - Result_Length := - Source'Length - Natural'Max (High - Low + 1, 0) + By'Length; + end if; + if High >= Low then declare + Front_Len : constant Integer := + Integer'Max (0, Low - Source'First); + -- Length of prefix of Source copied to result + + Back_Len : constant Integer := + Integer'Max (0, Source'Last - High); + -- Length of suffix of Source copied to result + + Result_Length : constant Integer := + Front_Len + By'Length + Back_Len; + -- Length of result + Result : Wide_Wide_String (1 .. Result_Length); begin - if High >= Low then - Result := - Source (Source'First .. Low - 1) & By & - Source (High + 1 .. Source'Last); - else - Result := Source (Source'First .. Low - 1) & By & - Source (Low .. Source'Last); - end if; + 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; + + else + return Insert (Source, Before => Low, New_Item => By); end if; end Replace_Slice; |