[Libguestfs] [PATCH v12 08/11] daemon: Implement inspection types and utility functions.

Pino Toscano ptoscano at redhat.com
Tue Sep 19 14:28:12 UTC 2017


On Wednesday, 9 August 2017 19:23:43 CEST Richard W.M. Jones wrote:
> +let parse_version_from_major_minor str data =
> +  if verbose () then
> +    eprintf "parse_version_from_major_minor: parsing '%s'\n%!" str;
> +
> +  if PCRE.matches re_major_minor str ||
> +     PCRE.matches re_major_no_minor str then (
> +    let major =
> +      try Some (int_of_string (PCRE.sub 1))
> +      with Not_found | Invalid_argument _ | Failure _ -> None in
> +    let minor =
> +      try Some (int_of_string (PCRE.sub 2))
> +      with Not_found | Invalid_argument _ | Failure _ -> None in
> +    match major, minor with
> +    | None, None
> +    | None, Some _ -> ()
> +    | Some major, None -> data.version <- Some (major, 0)
> +    | Some major, Some minor -> data.version <- Some (major, minor)
> +  )

IMHO this is more complex than needed:

  if PCRE.matches re_major_minor str (
    let major = int_of_string (PCRE.sub 1) in
    let minor = int_of_string (PCRE.sub 2) in
    data.version <- Some (major, minor)
  )
  else if PCRE.matches re_major_no_minor str then (
    let major = int_of_string (PCRE.sub 1) in
    data.version <- Some (major, 0)
  )

After all, the regexps should already ensure the captures are
available, and that they caught integer values.


-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170919/bccecc4b/attachment.sig>


More information about the Libguestfs mailing list