[messages] add support for spaces in messages array

- add special delimiters ([]) for arrays (which are now forbidden
  characters)
- backward compatible with old format if no spaces in array
This commit is contained in:
Gautier Hattenberger
2014-03-26 15:35:58 +01:00
parent 03d3e8386b
commit 8faa23d074
3 changed files with 21 additions and 5 deletions
+15 -2
View File
@@ -160,7 +160,7 @@ let rec string_of_value = function
| Int64 x -> Int64.to_string x
| Char c -> String.make 1 c
| String s -> s
| Array a -> String.concat separator (Array.to_list (Array.map string_of_value a))
| Array a -> "["^(String.concat separator (Array.to_list (Array.map string_of_value a)))^"]"
let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format)
@@ -661,8 +661,21 @@ module MessagesOfXml(Class:CLASS_Xml) = struct
let space = Str.regexp "[ \t]+"
let array_sep = Str.regexp "\\[\\|\\]"
let values_of_string = fun s ->
match Str.split space s with
(* split arguments and arrays *)
let array_split = Str.full_split array_sep s in
let rec loop = fun fields ->
match fields with
| [] -> []
| (Str.Delim "[")::((Str.Text l)::[Str.Delim "]"]) -> [l]
| (Str.Delim "[")::((Str.Text l)::((Str.Delim "]")::xs)) -> [l] @ (loop xs)
| [Str.Text x] -> Str.split space x
| (Str.Text x)::xs -> (Str.split space x) @ (loop xs)
| (Str.Delim _)::_ -> failwith "Pprz.values_of_string: incorrect array delimiter"
in
let msg_split = loop array_split in
match msg_split with
msg_name::args ->
begin
try