Displaying 6 results from an estimated 6 matches for "split_key_value_str".
2017 Oct 16
3
[PATCH v2 0/2] daemon: add and use split_key_value_strings helper
Changes from v1 to v2:
- split the "simple unquoting" as helper
- pass the unquoting function to split_key_value_strings
- use right unquoting function when applying split_key_value_strings
Pino Toscano (2):
daemon: add split_key_value_strings helper
daemon: use split_key_value_strings
daemon/inspect_fs_unix.ml | 93 +++++++++++++++++++----------------------------
daemon/md.ml | 9 ++---
daem...
2017 Oct 16
2
Re: [PATCH v2 1/2] daemon: add split_key_value_strings helper
.../www.freedesktop.org/software/systemd/man/os-release.html
os-release uses some kind of escaping system. It does look as if
shell_unquote may be appropriate here. (Of course whether writers of
/etc/os-release are doing the right thing is another issue. I guess
there is no validation).
> +let split_key_value_strings ?unquote lines =
Can we call this function something like ‘parse_key_value_file’? Most
of our other parsing functions are called ‘parse_xxx’, where as
‘*split*’ functions are generally reserved for functions that split a
single string.
Rich.
> + let lines = List.filter ((<>) "...
2017 Oct 16
4
[PATCH 1/3] daemon: add split_key_value_strings helper
.../daemon/utils.ml
+++ b/daemon/utils.ml
@@ -229,3 +229,18 @@ let unix_canonical_path path =
let path = String.nsplit "/" path in
let path = List.filter ((<>) "") path in
(if is_absolute then "/" else "") ^ String.concat "/" path
+
+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
+ let value =
+ let n = String.length value...
2017 Oct 16
0
[PATCH v2 1/2] daemon: add split_key_value_strings helper
...cat "/" path
+
+let simple_unquote s =
+ let n = String.length s in
+ if n >= 2 &&
+ ((s.[0] = '"' && s.[n-1] = '"') || (s.[0] = '\'' && s.[n-1] = '\'')) then
+ String.sub s 1 (n-2)
+ else
+ s
+
+let split_key_value_strings ?unquote lines =
+ let lines = List.filter ((<>) "") lines in
+ let lines = List.filter (fun s -> s.[0] <> '#') lines in
+ let lines = List.map (String.split "=") lines in
+ match unquote with
+ | None -> lines
+ | Some f -> List.map (fun (...
2017 Oct 16
0
Re: [PATCH v2 1/2] daemon: add split_key_value_strings helper
...escaping system. It does look as if
> shell_unquote may be appropriate here. (Of course whether writers of
> /etc/os-release are doing the right thing is another issue. I guess
> there is no validation).
Yes, this is what patch #2 already does, in parse_os_release:
+ let values = split_key_value_strings ~unquote:shell_unquote lines in
simple_unquote is used for parse_lsb_release: I could not find any
standard documentation for its format, and the examples I have have
either no quoting, or double quoting.
> > +let split_key_value_strings ?unquote lines =
>
> Can we call this func...
2017 Oct 16
3
[PATCH v3 0/2] daemon: add and use parse_key_value_strings helper
Changes from v2 to v3:
- split_key_value_strings renamed to parse_key_value_strings
Changes from v1 to v2:
- split the "simple unquoting" as helper
- pass the unquoting function to split_key_value_strings
- use right unquoting function when applying split_key_value_strings
Pino Toscano (2):
daemon: add split_key_value_strings he...