[ocaml] support display of formatted string in messages

this should close #796
to display an integer (or array of integer) in HEX, just add format="%x" to the field in messages.xml
This commit is contained in:
Gautier Hattenberger
2014-10-20 23:41:34 +02:00
parent bc4df1d4f0
commit d616131156
3 changed files with 13 additions and 4 deletions
+8 -3
View File
@@ -168,10 +168,15 @@ let rec string_of_value = function
let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format)
let formatted_string_of_value = fun format v ->
let rec formatted_string_of_value = fun format v ->
match v with
Float x -> sprintf (magic format) x
| v -> string_of_value v
| Int x -> sprintf (magic format) x
| Float x -> sprintf (magic format) x
| Int32 x -> sprintf (magic format) x
| Int64 x -> sprintf (magic format) x
| Char x -> sprintf (magic format) x
| String x -> sprintf (magic format) x
| Array a -> "|"^(String.concat separator (Array.to_list (Array.map (formatted_string_of_value format) a)))^"|"
let sizeof = fun f ->
+1
View File
@@ -63,6 +63,7 @@ val is_fixed_array_type : string -> bool
val size_of_field : field -> int
val string_of_value : value -> string
val formatted_string_of_value : 'a -> value -> string
val int_of_value : value -> int (* May raise Invalid_argument *)
type type_descr = {
format : string ;