[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [libosinfo] Match substring regex in the end



On Mon, Feb 06, 2012 at 08:23:01PM +0100, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
> 
> Sometimes volume-id expression of one architecture is a substring of
> volume-id expression of another architecture for the same OS. For
> example '.*G.*RMC.*' is volume-id expression for i386 media of win7,
> while '.*G.*RMC.*X.*' is for x86_64. To avoid incorrect matching, we
> need to ensure that matching is done against '.*G.*RMC.*X.*' first and
> then '.*G.*RMC.*'.
> ---
>  osinfo/osinfo_db.c |   20 ++++++++++++++++++++
>  1 files changed, 20 insertions(+), 0 deletions(-)
> 
> diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
> index 0e90f6e..b5ac506 100644
> --- a/osinfo/osinfo_db.c
> +++ b/osinfo/osinfo_db.c
> @@ -321,6 +321,24 @@ void osinfo_db_add_deployment(OsinfoDb *db, OsinfoDeployment *deployment)
>      osinfo_list_add(OSINFO_LIST(db->priv->deployments), OSINFO_ENTITY(deployment));
>  }
>  
> +static gint media_volume_compare (gconstpointer a, gconstpointer b)
> +{
> +    OsinfoMedia *media_a = OSINFO_MEDIA(a);
> +    OsinfoMedia *media_b = OSINFO_MEDIA(b);
> +    const gchar *volume_a = osinfo_media_get_volume_id(media_a);
> +    const gchar *volume_b = osinfo_media_get_volume_id(media_b);
> +
> +    if (volume_a == NULL || volume_b == NULL)
> +        /* Order doesn't matter then */
> +        return 0;
> +
> +    if (strstr(volume_a, volume_b) != NULL)
> +        return -1;
> +    else
> +        /* Sub-string comes later */
> +        return 1;
> +}

Alternatively, I think sorting the regexp by length would work too even if
it's less accurate.

Christophe

Attachment: pgpfGXH3uheRK.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]