Skip to content

Commit

Permalink
Merge branch 'topic/vadim/delete' into 'master'
Browse files Browse the repository at this point in the history
Virtual_String_Vector.Join with string separator

See merge request eng/ide/VSS!340
  • Loading branch information
godunko committed Nov 7, 2024
2 parents 2f9babd + 3c3156d commit 334090a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
26 changes: 26 additions & 0 deletions source/text/implementation/vss-string_vectors.adb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,32 @@ package body VSS.String_Vectors is
end return;
end Join;

----------
-- Join --
----------

function Join
(Self : Virtual_String_Vector'Class;
Separator : VSS.Strings.Virtual_String)
return VSS.Strings.Virtual_String
is
First_Segment : Boolean := True;

begin
return Result : VSS.Strings.Virtual_String do
for Item of Self loop
if First_Segment then
First_Segment := False;

else
Result.Append (Separator);
end if;

Result.Append (Item);
end loop;
end return;
end Join;

----------------
-- Join_Lines --
----------------
Expand Down
4 changes: 4 additions & 0 deletions source/text/vss-string_vectors.ads
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ package VSS.String_Vectors is
(Self : Virtual_String_Vector'Class;
Separator : VSS.Characters.Virtual_Character)
return VSS.Strings.Virtual_String;
function Join
(Self : Virtual_String_Vector'Class;
Separator : VSS.Strings.Virtual_String)
return VSS.Strings.Virtual_String;
-- Join all strings in the string vector into single string with each
-- element separated by the given separator.

Expand Down
38 changes: 38 additions & 0 deletions testsuite/text/test_string_vector.adb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ procedure Test_String_Vector is
-- Testcases

procedure Test_Legacy_Tests;
procedure Test_Join_String;
procedure Test_Join_Lines;
procedure Test_Is_Empty;
procedure Test_Append_Vector;
Expand Down Expand Up @@ -305,6 +306,41 @@ procedure Test_String_Vector is
end;
end Test_Join_Lines;

----------------------
-- Test_Join_String --
----------------------

procedure Test_Join_String is
begin
-- Usual case

declare
V : constant VSS.String_Vectors.Virtual_String_Vector :=
["ABC", "DEF", "GHI"];

begin
Test_Support.Assert (V.Join ("") = "ABCDEFGHI");
Test_Support.Assert (V.Join (",") = "ABC,DEF,GHI");
Test_Support.Assert (V.Join ("=>") = "ABC=>DEF=>GHI");
end;

-- Empty vector

declare
VE : VSS.String_Vectors.Virtual_String_Vector;

begin
Test_Support.Assert (VE.Join ("").Is_Empty);
Test_Support.Assert (VE.Join ("").Is_Null);

Test_Support.Assert (VE.Join (",").Is_Empty);
Test_Support.Assert (VE.Join (",").Is_Null);

Test_Support.Assert (VE.Join ("=>").Is_Empty);
Test_Support.Assert (VE.Join ("=>").Is_Null);
end;
end Test_Join_String;

-----------------------
-- Test_Legacy_Tests --
-----------------------
Expand Down Expand Up @@ -436,6 +472,8 @@ procedure Test_String_Vector is
begin
Test_Support.Run_Testcase
(Test_Legacy_Tests'Access, "Various legacy tests");
Test_Support.Run_Testcase
(Test_Join_String'Access, "Join String Separator");
Test_Support.Run_Testcase (Test_Join_Lines'Access, "Join_Lines");
Test_Support.Run_Testcase (Test_Is_Empty'Access, "Is_Empty");
Test_Support.Run_Testcase (Test_Append_Vector'Access, "Append (Vector)");
Expand Down

0 comments on commit 334090a

Please sign in to comment.