[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paparazzi-commits] [4029] modify subst_child (may raise Not_found)
From: |
Pascal Brisset |
Subject: |
[paparazzi-commits] [4029] modify subst_child (may raise Not_found) |
Date: |
Sun, 30 Aug 2009 19:39:15 +0000 |
Revision: 4029
http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4029
Author: hecto
Date: 2009-08-30 19:39:14 +0000 (Sun, 30 Aug 2009)
Log Message:
-----------
modify subst_child (may raise Not_found)
add subst_or_add_child
Modified Paths:
--------------
paparazzi3/trunk/sw/lib/ocaml/extXml.ml
paparazzi3/trunk/sw/lib/ocaml/extXml.mli
Modified: paparazzi3/trunk/sw/lib/ocaml/extXml.ml
===================================================================
--- paparazzi3/trunk/sw/lib/ocaml/extXml.ml 2009-08-30 19:37:47 UTC (rev
4028)
+++ paparazzi3/trunk/sw/lib/ocaml/extXml.ml 2009-08-30 19:39:14 UTC (rev
4029)
@@ -178,12 +178,26 @@
let subst_child = fun ?(select= fun _ -> true) t x xml ->
match xml with
Xml.Element (tag, attrs, children) ->
- Xml.Element (tag,
- attrs,
- List.map (fun xml -> if tag_is xml t && select xml then x
else xml) children)
+ let found = ref false in
+ let new_children =
+ List.map
+ (fun xml -> if tag_is xml t && select xml then (found := true; x)
else xml)
+ children in
+ if !found then
+ Xml.Element (tag, attrs, new_children)
+ else
+ raise Not_found
| Xml.PCData _ -> xml
+let subst_or_add_child = fun t x xml ->
+ try subst_child t x xml with Not_found ->
+ match xml with
+ Xml.Element (tag, attrs, children) ->
+ Xml.Element (tag, attrs, x::children)
+ | Xml.PCData _ -> xml
+
+
let remove_child = fun ?(select= fun _ -> true) t xml ->
match xml with
Xml.Element (tag, attrs, children) ->
Modified: paparazzi3/trunk/sw/lib/ocaml/extXml.mli
===================================================================
--- paparazzi3/trunk/sw/lib/ocaml/extXml.mli 2009-08-30 19:37:47 UTC (rev
4028)
+++ paparazzi3/trunk/sw/lib/ocaml/extXml.mli 2009-08-30 19:39:14 UTC (rev
4029)
@@ -58,11 +58,14 @@
val subst_child :
?select:(Xml.xml -> bool) -> string -> Xml.xml -> Xml.xml -> Xml.xml
-(** [subst_child ?select child_tag new_child xml] *)
+(** [subst_child ?select child_tag new_child xml] May raise Not_found *)
+val subst_or_add_child : string -> Xml.xml -> Xml.xml -> Xml.xml
+(** [subst_or_add_child child_tag new_child xml] *)
+
val remove_child :
?select:(Xml.xml -> bool) -> string -> Xml.xml -> Xml.xml
-(** [delete_child ?select child_tag xml] *)
+(** [delete_child ?select child_tag xml] Returns [xml] if not found *)
val parse_file : ?noprovedtd:bool -> string -> Xml.xml
(** Identical to Xml.parse_file with Failure exceptions. [nodtdprove] default
is false. *)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paparazzi-commits] [4029] modify subst_child (may raise Not_found),
Pascal Brisset <=