Search by property

This commit is contained in:
A
2018-02-26 15:34:13 +01:00
parent 86e96bf6b7
commit c0283e2566
5 changed files with 76 additions and 3 deletions
+3 -3
View File
@@ -4,12 +4,12 @@ package Alire.Index.PragmARC is
Repo : constant URL := "https://github.com/alire-project/PragmARC.git";
Desc : constant Project_Description :=
"PragmAda Reusable Components (PragmARCs), open-source Ada components";
"PragmAda Reusable Components (PragmARCs), ";
V_2017 : constant Release := -- Experimental '07 version
Register (Name,
V ("2017.2007.0"),
Desc,
Desc & "ISO/IEC 8652:2007 version",
Git (Repo, "db6c1730fe825f8303c60b48f82db08bd408588d"),
Properties =>
Executable ("compile_all") and
@@ -22,7 +22,7 @@ package Alire.Index.PragmARC is
V_2011 : constant Release := -- Pure Ada95 version
Register (Name,
V ("2011.1995.0"),
Desc,
Desc & "Ada 95 version",
Git (Repo, "34b0e12b5f9aea63408c94cc48ba7a16687c8d76"),
Properties =>
Executable ("compile_all") and
+26
View File
@@ -62,4 +62,30 @@ package body Alire.Releases is
end if;
end Print;
-----------------------
-- Property_Contains --
-----------------------
function Property_Contains (R : Release; Str : String) return Boolean is
use Utils;
Search : constant String := To_Lower_Case (Str);
begin
for P of R.Props loop
declare
Text : constant String :=
To_Lower_Case
((if Utils.Contains (P.Image, ":")
then Utils.Tail (P.Image, ':')
else P.Image));
begin
if Utils.Contains (Text, Search) then
return True;
end if;
end;
end loop;
return False;
end Property_Contains;
end Alire.Releases;
+5
View File
@@ -53,6 +53,11 @@ package Alire.Releases with Preelaborate is
procedure Print (R : Release);
-- Dump info to console
-- Search helpers
function Property_Contains (R : Release; Str : String) return Boolean;
-- True if some property contains the given string
private
+35
View File
@@ -1,7 +1,42 @@
with Ada.Strings.Fixed;
with GNAT.Case_Util;
package body Alire.Utils is
--------------
-- Contains --
--------------
function Contains (Text : String; Sub : String) return Boolean is
(Ada.Strings.Fixed.Count (Text, Sub) > 0);
----------
-- Tail --
----------
function Tail (Str : String; Separator : Character) return String is
begin
for I in Str'Range loop
if Str (I) = Separator then
return Str (I + 1 .. Str'Last);
end if;
end loop;
return "";
end Tail;
-------------------
-- To_Lower_Case --
-------------------
function To_Lower_Case (S : String) return String is
begin
return SLC : String := S do
GNAT.Case_Util.To_Lower (SLC);
end return;
end To_Lower_Case;
-------------------
-- To_Mixed_Case --
-------------------
+7
View File
@@ -2,9 +2,16 @@ with Ada.Containers.Indefinite_Vectors;
package Alire.Utils with Preelaborate is
function To_Lower_Case (S : String) return String;
function To_Mixed_Case (S : String) return String;
function Contains (Text : String; Sub : String) return Boolean;
package String_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, String);
subtype String_Vector is String_Vectors.Vector;
function Tail (Str : String; Separator : Character) return String;
-- If Str contains Separator, the rhs is returned
-- Otherwise ""
end Alire.Utils;