ocaml: phase 6 Printf %i/%u/%x/%X/%o + int_to_hex/octal host primitives (+5 tests, 533 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s
Three new host primitives in eval.sx: _int_to_hex_lower n -> string of hex digits (lowercase) _int_to_hex_upper n -> string of hex digits (uppercase) _int_to_octal n -> string of octal digits Each builds the digit string by repeated floor(n / base) + mod, prepending the digit at each step. Negative numbers prefix '-' so the output round-trips through int_of_string with a sign. Printf walker now fans out: %d, %i, %u -> _string_of_int %f -> _string_of_float %x -> _int_to_hex_lower %X -> _int_to_hex_upper %o -> _int_to_octal %s, %c, %b -> existing handling Printf.sprintf '%x' 255 = 'ff' Printf.sprintf '%X' 4096 = '1000' Printf.sprintf '%o' 8 = '10' Printf.sprintf '%x %X %o' 255 4096 8 = 'ff 1000 10'
This commit is contained in:
@@ -524,12 +524,18 @@
|
||||
else if pos + 1 < n && _string_get fmt pos = \"%\" then
|
||||
let spec = _string_get fmt (pos + 1) in
|
||||
if spec = \"%\" then walk (pos + 2) (prefix ^ \"%\")
|
||||
else if spec = \"d\" || spec = \"s\" || spec = \"f\"
|
||||
|| spec = \"c\" || spec = \"b\" then
|
||||
else if spec = \"d\" || spec = \"i\" || spec = \"s\"
|
||||
|| spec = \"f\" || spec = \"c\" || spec = \"b\"
|
||||
|| spec = \"x\" || spec = \"X\" || spec = \"o\"
|
||||
|| spec = \"u\" then
|
||||
(fun arg ->
|
||||
let s =
|
||||
if spec = \"d\" then _string_of_int arg
|
||||
if spec = \"d\" || spec = \"i\" || spec = \"u\"
|
||||
then _string_of_int arg
|
||||
else if spec = \"f\" then _string_of_float arg
|
||||
else if spec = \"x\" then _int_to_hex_lower arg
|
||||
else if spec = \"X\" then _int_to_hex_upper arg
|
||||
else if spec = \"o\" then _int_to_octal arg
|
||||
else if spec = \"b\" then
|
||||
(if arg then \"true\" else \"false\")
|
||||
else arg
|
||||
|
||||
Reference in New Issue
Block a user