diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-09-02 13:03:12 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-09-02 13:03:12 +0200 |
commit | d33442c2576793420802bbd54127923079c487c4 (patch) | |
tree | b6e0499807b85c4b1500a9905e77379ba083386f /src | |
parent | 05b086a782eeee8c2b0566660d942ec0909da6fb (diff) | |
download | vyconf-d33442c2576793420802bbd54127923079c487c4.tar.gz vyconf-d33442c2576793420802bbd54127923079c487c4.zip |
Add support for node renaming.
Diffstat (limited to 'src')
-rw-r--r-- | src/vytree.ml | 12 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/vytree.ml b/src/vytree.ml index b200cc4..57c3612 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -43,6 +43,11 @@ let replace node child = let children' = Vylist.replace (fun x -> x.name = name) child children in { node with children = children' } +let replace_full node child name = + let children = node.children in + let children' = Vylist.replace (fun x -> x.name = name) child children in + { node with children = children' } + let find node name = Vylist.find (fun x -> x.name = name) node.children @@ -131,6 +136,13 @@ let rec insert_multi_level default_data node path_done path_remaining data = let delete node path = do_with_child delete_immediate node path +let rename node path newname = + let rename_immediate newname' node' name' = + let child = find_or_fail node' name' in + let child = { child with name=newname' } in + replace_full node' child name' + in do_with_child (rename_immediate newname) node path + let update node path data = let update_data data' node' name = let child = find_or_fail node' name in diff --git a/src/vytree.mli b/src/vytree.mli index da593f1..556ca77 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -29,6 +29,8 @@ val delete : 'a t -> string list -> 'a t val update : 'a t -> string list -> 'a -> 'a t +val rename : 'a t -> string list -> string -> 'a t + val list_children : 'a t -> string list val get : 'a t -> string list -> 'a t |