Skip to content

Commit a1d09fe

Browse files
committed
Merge branch 'topic/vadim/delete' into 'main'
Fix delete of slice from an empty string Closes #5 See merge request eng/shared/vss-text!7
2 parents 7f18958 + 6d01929 commit a1d09fe

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

source/text/implementation/vss-implementation-utf8_strings.adb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,17 @@ package body VSS.Implementation.UTF8_Strings is
108108
Success : Boolean with Unreferenced;
109109

110110
begin
111-
if From.Index > To.Index then
111+
if Text.Size = 0 then
112+
-- An empty string, all components of `Size` are zeros.
113+
114+
pragma Assert (From.UTF8_Offset = -1);
115+
pragma Assert (To.UTF8_Offset = -1);
116+
-- The only possible position of the cursors is before the first
117+
-- charater.
118+
119+
Size := (0, 0, 0);
120+
121+
elsif From.Index > To.Index then
112122
Size := (0, 0, 0);
113123

114124
else

testsuite/text/test_string-test_delete.adb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,25 @@ begin
7474
Test_Support.Assert (SB = " Ada_With_Private_Absent,");
7575
Test_Support.Assert (S = " ,");
7676
end;
77+
78+
-- vss-text#5
79+
--
80+
-- Check that `Delete` of the slice from last character to last character
81+
-- in the null and an empty string doesn't raise exception.
82+
83+
declare
84+
SN : VSS.Strings.Virtual_String;
85+
SE : VSS.Strings.Virtual_String := "";
86+
87+
begin
88+
SN.Delete (SN.At_Last_Character, SN.At_Last_Character);
89+
Test_Support.Assert (SN.Is_Null);
90+
Test_Support.Assert (SN.Is_Empty);
91+
Test_Support.Assert (SN = SN);
92+
93+
SE.Delete (SE.At_Last_Character, SE.At_Last_Character);
94+
Test_Support.Assert (not SE.Is_Null);
95+
Test_Support.Assert (SE.Is_Empty);
96+
Test_Support.Assert (SE = SE);
97+
end;
7798
end Test_Delete;

0 commit comments

Comments
 (0)