[Libguestfs] [PATCH 1/3] daemon: add split_key_value_strings helper

Richard W.M. Jones rjones at redhat.com
Mon Oct 16 14:56:42 UTC 2017


This seems like quite a specific function.  Is there not an Augeas
lens for this file.  It would solve this more elegantly.

> +let split_key_value_strings lines =
> +  let lines = List.filter ((<>) "") lines in
> +  let lines = List.filter (fun s -> s.[0] <> '#') lines in
> +  List.map (
> +    fun line ->
> +      let key, value = String.split "=" line in

PCRE?  Is whitespace significant?

> +      let value =
> +        let n = String.length value in
> +        if n >= 2 && value.[0] = '"' && value.[n-1] = '"' then
> +          String.sub value 1 (n-2)

Maybe use shell_unquote from C_utils?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list