Skip to content

Commit 41d5f40

Browse files
committedNov 30, 2009
Introducing nop format delimiter %,
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9429 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent ada3c31 commit 41d5f40

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed
 

‎stdlib/printf.ml

+4-28
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let iter_on_format_args fmt add_conv add_char =
215215
and scan_conv skip i =
216216
if i > lim then incomplete_format fmt else
217217
match Sformat.unsafe_get fmt i with
218-
| '%' | '!' -> succ i
218+
| '%' | '!' | ',' -> succ i
219219
| 's' | 'S' | '[' -> add_conv skip i 's'
220220
| 'c' | 'C' -> add_conv skip i 'c'
221221
| 'd' | 'i' |'o' | 'u' | 'x' | 'X' | 'N' -> add_conv skip i 'i'
@@ -431,8 +431,6 @@ let get_index spec n =
431431
(* Format a float argument as a valid Caml lexeme. *)
432432
let format_float_lexeme =
433433

434-
let lexeme_buff = Buffer.create 32 in
435-
436434
(* To be revised: this procedure should be a unique loop that performs the
437435
validity check and the string lexeme modification at the same time.
438436
Otherwise, it is too difficult to handle the strange padding facilities
@@ -446,35 +444,12 @@ let format_float_lexeme =
446444
*)
447445

448446
let make_valid_float_lexeme s =
449-
let l = String.length s in
450-
(* This should never occur. *)
451-
if l = 0 then "nan" else
452-
453-
let add_dot s i =
454-
let rec add_dot_loop i =
455-
if i >= l then Buffer.add_char lexeme_buff '.' else
456-
match s.[i] with
457-
| '+' ->
458-
(* Depending of the ``style'' this should be a space or a 0.
459-
Let start by using a space. *)
460-
Buffer.add_char lexeme_buff ' ';
461-
add_dot_loop (i + 1)
462-
| c ->
463-
Buffer.add_char lexeme_buff c;
464-
add_dot_loop (i + 1) in
465-
add_dot_loop i in
466-
467447
(* Check if s is already a valid lexeme:
468448
in this case do nothing (we should still remove a leading +!),
469449
otherwise turn s into a valid Caml lexeme. *)
450+
let l = String.length s in
470451
let rec valid_float_loop i =
471-
if i >= l then begin
472-
Buffer.clear lexeme_buff;
473-
add_dot s 0;
474-
let res = Buffer.contents lexeme_buff in
475-
Buffer.clear lexeme_buff;
476-
res
477-
end else
452+
if i >= l then s ^ "." else
478453
match s.[i] with
479454
(* Sure, this is already a valid float lexeme. *)
480455
| '.' | 'e' | 'E' -> s
@@ -598,6 +573,7 @@ let scan_format fmt args n pos cont_s cont_a cont_t cont_f cont_m =
598573
let s = format_int (extract_format_int 'n' fmt pos i widths) x in
599574
cont_s (next_index spec n) s (succ i)
600575
end
576+
| ',' -> cont_s n "" (succ i)
601577
| '!' -> cont_f n (succ i)
602578
| '{' | '(' as conv (* ')' '}' *) ->
603579
let (xf : ('a, 'b, 'c, 'd, 'e, 'f) format6) = get_arg spec n in

0 commit comments

Comments
 (0)