Original bug ID: 6942
Reporter: acascella
Status: acknowledged (set by @damiendoligez on 2016-11-08T10:19:06Z)
Resolution: open
Priority: low
Severity: feature
Platform: x86_64
OS: GNU/Linux
OS Version: 3.13.0-57-generi
Version: 4.02.2
Category: standard library
Monitored by: @gasche
Bug description
I noticed that precision in formatters for strings is ignored. For instance Printf.printf "%.2" "Hello" will print "Hello".
In C, the equivalent call would print only the first two chars, "He". The precision is interpreted as the maximum number of bytes to be written to the output.
I know that the OCaml documentation for Printf doesn't specify the behavior of precision for strings, so this is not a bug. I was only wondering if there is a reason for not handling precision for strings, or if it will be a desirable feature to add.
Steps to reproduce
OCaml version 4.02.2
Printf.printf "%s" "Hello";;
Hello- : unit = ()
Printf.printf "%.2s" "Hello" ;;
Hello- : unit = ()
Original bug ID: 6942
Reporter: acascella
Status: acknowledged (set by @damiendoligez on 2016-11-08T10:19:06Z)
Resolution: open
Priority: low
Severity: feature
Platform: x86_64
OS: GNU/Linux
OS Version: 3.13.0-57-generi
Version: 4.02.2
Category: standard library
Monitored by: @gasche
Bug description
I noticed that precision in formatters for strings is ignored. For instance Printf.printf "%.2" "Hello" will print "Hello".
In C, the equivalent call would print only the first two chars, "He". The precision is interpreted as the maximum number of bytes to be written to the output.
I know that the OCaml documentation for Printf doesn't specify the behavior of precision for strings, so this is not a bug. I was only wondering if there is a reason for not handling precision for strings, or if it will be a desirable feature to add.
Steps to reproduce
OCaml version 4.02.2
Printf.printf "%s" "Hello";;
Hello- : unit = ()
Printf.printf "%.2s" "Hello" ;;
Hello- : unit = ()