Skip to content

Commit

Permalink
Set -> Vector -> Set conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Aug 29, 2023
1 parent c3b5a19 commit ecc3877
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/aaa-strings.adb
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,39 @@ package body AAA.Strings is
-- To_Vector --
---------------

function To_Vector (This : Set) return Vector is
begin
return V : Vector do
for Elem of This loop
V.Append (Elem);
end loop;
end return;
end To_Vector;

---------------
-- To_Vector --
---------------

function To_Vector (S : String) return Vector is
begin
return V : Vector do
V.Append (S);
end return;
end To_Vector;

------------
-- To_Set --
------------

function To_Set (V : Vector'Class) return Set is
begin
return S : Set do
for Elem of V loop
S.Include (Elem);
end loop;
end return;
end To_Set;

----------
-- Trim --
----------
Expand Down
7 changes: 7 additions & 0 deletions src/aaa-strings.ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ with Ada.Containers.Indefinite_Vectors;

package AAA.Strings with Preelaborate is

type Vector;

function Camel_To_Mixed (S : String) return String;
-- Converts ThisThing into This_Thing

Expand Down Expand Up @@ -86,6 +88,8 @@ package AAA.Strings with Preelaborate is

Empty_Set : constant Set;

function To_Vector (This : Set) return Vector;

-------------
-- Vectors --
-------------
Expand Down Expand Up @@ -180,6 +184,9 @@ package AAA.Strings with Preelaborate is
-- Return V without its first element. If Allow_Empty, tail of an empty
-- vector will be another empty vector.

function To_Set (V : Vector'Class) return Set;
-- Note that this will drop duplicates

not overriding
function To_Vector (S : String) return Vector;

Expand Down

0 comments on commit ecc3877

Please sign in to comment.