From c0283e256600977469493d9d40224d93ca253a4b Mon Sep 17 00:00:00 2001 From: A Date: Mon, 26 Feb 2018 15:34:13 +0100 Subject: [PATCH] Search by property --- index/alire-index-pragmarc.ads | 6 +++--- src/alire-releases.adb | 26 +++++++++++++++++++++++++ src/alire-releases.ads | 5 +++++ src/alire-utils.adb | 35 ++++++++++++++++++++++++++++++++++ src/alire-utils.ads | 7 +++++++ 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/index/alire-index-pragmarc.ads b/index/alire-index-pragmarc.ads index 16efa81f..f7638d96 100644 --- a/index/alire-index-pragmarc.ads +++ b/index/alire-index-pragmarc.ads @@ -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 diff --git a/src/alire-releases.adb b/src/alire-releases.adb index c11e823f..a14ab6f0 100644 --- a/src/alire-releases.adb +++ b/src/alire-releases.adb @@ -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; diff --git a/src/alire-releases.ads b/src/alire-releases.ads index cfb911b2..d09612cc 100644 --- a/src/alire-releases.ads +++ b/src/alire-releases.ads @@ -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 diff --git a/src/alire-utils.adb b/src/alire-utils.adb index 56def7d6..97d8803a 100644 --- a/src/alire-utils.adb +++ b/src/alire-utils.adb @@ -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 -- ------------------- diff --git a/src/alire-utils.ads b/src/alire-utils.ads index 439cfda8..2d82f3de 100644 --- a/src/alire-utils.ads +++ b/src/alire-utils.ads @@ -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;